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










