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();
}










