Mine Sweeper/ ¶
Python ¶
2005/ 2005/python ToyProblem
.
값 꾸.
.
값 꾸.
~cpp
def search():
for i in range(height):
for j in range(width):
if M[i][j]=='*':
if M[i-1][j-1]!= '*' and i-1>=0 and j-1>=0 and i-1<width and j-1<height:
M[i-1][j-1]=M[i-1][j-1]+1
if M[i-1][j]!= '*' and i-1>=0 and j>=0 and i-1<width and j<height:
M[i-1][j]=M[i-1][j]+1
if M[i-1][j+1]!= '*' and i-1>=0 and j+1>=0 and i-1<width and j+1<height:
M[i-1][j+1]=M[i][j+1]+1
if M[i][j-1]!= '*' and i>=0 and j-1>=0 and i<width and j-1<height:
M[i][j-1]=M[i][j-1]+1
if M[i][j+1]!= '*' and i>=0 and j+1>=0 and i<width and j+1<height:
M[i][j+1]=M[i][j+1]+1
if M[i+1][j-1]!= '*' and i+1>=0 and j-1>=0 and i+1<width and j-1<height:
M[i+1][j-1]=M[i+1][j-1]+1
if M[i+1][j]!= '*' and i+1>=0 and j>=0 and i+1<width and j<height:
M[i+1][j]=M[i+1][j]+1
if M[i+1][j+1]!= '*' and i+1>=0 and j+1>=0 and i+1<width and j+1<height:
M[i+1][j+1]=M[i+1][j+1]+1
width = 4
height = 4
M=[['*','.','.','.'],['.','.','.','.'],['.','*','.','.'],['.','.','.','.']]
for i in range(height):
for j in range(width):
if M[i][j]!='*':
M[i][j]=int(0)
search()
for i in range(height):
print M[i]
FLASH ¶
1기?? 기 각 .
객 고 ...-_-ㅋ;; C Array 객 ??;;
그 까 고 ;; ~;;
객 고 ...-_-ㅋ;; C Array 객 ??;;
그 까 고 ;; ~;;
. 굳 .
layer ()
~cpp
function set_val() {
///////////////////////// 갯 기 결
size = 15; //
quantityMine=100;// 갯
/////////////////////////////////////////////////////////////////////////
i = j = 0;
set_all_num = 0;
//size*size 2 set_all_num값 기
map = new Array();
for (i=0; i<size; i++) {
map[i] = new Array();
for (j=0; j<size; j++) {
map[i][j] = set_all_num;
}
}
trace("end set all value");
}
//
function setMine(){
mine_count = 0;
while(mine_count<quantityMine){
for (i=0; i<size; i++) {
for (j=0; j<size; j++) {
if( map[i][j]!= -1 && mine_count < quantityMine && !( random(100) % 5 ) ){
map[i][j]='*';
trace(" " + i + " " + j + " 금 까 갯 : " + ++mine_count);
}else{
}
}
}
}
}
// .
function showMineMap(){
trace(" ");
trace(" ");
trace(" ");
for(i=0; i<size; i++){
temp = new Array();
temp = map[i];
showMap=temp.join(" ");
trace(showMap);
}
trace(" ");
trace(" ");
trace(" ");
}
// 갯 고 .
function checkMineMap(){
minecount = 0;
for(i=0; i<size; i++){
for(j=0; j<size; j++){
if(map[i][j]!='*'){
if(map[i-1][j-1]=='*')minecount++;
if(map[i-1][j]=='*')minecount++;
if(map[i-1][j+1]=='*')minecount++;
if(map[i][j-1]=='*')minecount++;
if(map[i][j+1]=='*')minecount++;
if(map[i+1][j-1]=='*')minecount++;
if(map[i+1][j]=='*')minecount++;
if(map[i+1][j+1]=='*')minecount++;
map[i][j]=minecount;
}
minecount=0;
}
}
}
blank symbol : 기고 .
~cpp
onClipEvent(load){
// 기
_root.set_val();
// 0
_root.showMineMap();
//
_root.setMine();
//
_root.showMineMap();
// 갯 고 .
_root.checkMineMap();
//
_root.showMineMap();
}










