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










