#include "osalib.h"
static int w,k;
static char** mapa;
static const int dir[][2]={{0,1},{1,0},{-1,0},{0,-1}};
void NowaWyspa(int n, int m, char **board){
w=n,k=m;
mapa=board;
}
int NowaWarownia(int r, int c){
int d,licz_w=0,licz_d=0,stos_s=0,i,j,currW,currK,licz_odciete;
r--;c--;
for(d=0;d<4;d++){
if(r+dir[d][0]<w && r+dir[d][0]>=0 && c+dir[d][1]<k && c+dir[d][1]>=0){
if(mapa[r+dir[d][0]][c+dir[d][1]]=='W'){
licz_w++;
}else{
licz_d++;
}
}
}
if(licz_w==3||licz_w==4 ){
mapa[r][c]='W';
return 1;
}
short int* stosW=new short int[r*c];
short int* stosK=new short int[r*c];
stos_s=0;
for(i=0;i<w;i++){
for(j=0;j<k;j++){
if(mapa[i][j]=='K'){
mapa[i][j]='H';
stosW[stos_s]=i;
stosK[stos_s]=j;
stos_s++;
break;
}
}
if(stos_s)break;
}
mapa[r][c]='W';
while(stos_s>0){
currW=stosW[stos_s-1];
currK=stosK[stos_s-1];
stos_s--;
for(d=0;d<4;d++){
if(currW+dir[d][0]<w && currW+dir[d][0]>=0 && currK+dir[d][1]<k && currK+dir[d][1]>=0){
if(mapa[currW+dir[d][0]][currK+dir[d][1]]=='K'){
mapa[currW+dir[d][0]][currK+dir[d][1]]='H';
stosW[stos_s]=currW+dir[d][0];
stosK[stos_s]=currK+dir[d][1];
stos_s++;
}
if(mapa[currW+dir[d][0]][currK+dir[d][1]]=='.'){
mapa[currW+dir[d][0]][currK+dir[d][1]]=';';
stosW[stos_s]=currW+dir[d][0];
stosK[stos_s]=currK+dir[d][1];
stos_s++;
}
}
}
}
licz_odciete=0;
for(i=0;i<w;i++){
for(j=0;j<k;j++){
if(mapa[i][j]=='K'){
licz_odciete=1;
}
if(mapa[i][j]=='H'){
mapa[i][j]='K';
}
if(mapa[i][j]==';'){
mapa[i][j]='.';
}
}
}
if(licz_odciete==0){
return 1;
}
mapa[r][c]='.';
return 0;
}
void PrzeniesOsade(int r1, int c1, int r2, int c2){
mapa[r1-1][c1-1]='.';
mapa[r2-1][c2-1]='K';
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | #include "osalib.h" static int w,k; static char** mapa; static const int dir[][2]={{0,1},{1,0},{-1,0},{0,-1}}; void NowaWyspa(int n, int m, char **board){ w=n,k=m; mapa=board; } int NowaWarownia(int r, int c){ int d,licz_w=0,licz_d=0,stos_s=0,i,j,currW,currK,licz_odciete; r--;c--; for(d=0;d<4;d++){ if(r+dir[d][0]<w && r+dir[d][0]>=0 && c+dir[d][1]<k && c+dir[d][1]>=0){ if(mapa[r+dir[d][0]][c+dir[d][1]]=='W'){ licz_w++; }else{ licz_d++; } } } if(licz_w==3||licz_w==4 ){ mapa[r][c]='W'; return 1; } short int* stosW=new short int[r*c]; short int* stosK=new short int[r*c]; stos_s=0; for(i=0;i<w;i++){ for(j=0;j<k;j++){ if(mapa[i][j]=='K'){ mapa[i][j]='H'; stosW[stos_s]=i; stosK[stos_s]=j; stos_s++; break; } } if(stos_s)break; } mapa[r][c]='W'; while(stos_s>0){ currW=stosW[stos_s-1]; currK=stosK[stos_s-1]; stos_s--; for(d=0;d<4;d++){ if(currW+dir[d][0]<w && currW+dir[d][0]>=0 && currK+dir[d][1]<k && currK+dir[d][1]>=0){ if(mapa[currW+dir[d][0]][currK+dir[d][1]]=='K'){ mapa[currW+dir[d][0]][currK+dir[d][1]]='H'; stosW[stos_s]=currW+dir[d][0]; stosK[stos_s]=currK+dir[d][1]; stos_s++; } if(mapa[currW+dir[d][0]][currK+dir[d][1]]=='.'){ mapa[currW+dir[d][0]][currK+dir[d][1]]=';'; stosW[stos_s]=currW+dir[d][0]; stosK[stos_s]=currK+dir[d][1]; stos_s++; } } } } licz_odciete=0; for(i=0;i<w;i++){ for(j=0;j<k;j++){ if(mapa[i][j]=='K'){ licz_odciete=1; } if(mapa[i][j]=='H'){ mapa[i][j]='K'; } if(mapa[i][j]==';'){ mapa[i][j]='.'; } } } if(licz_odciete==0){ return 1; } mapa[r][c]='.'; return 0; } void PrzeniesOsade(int r1, int c1, int r2, int c2){ mapa[r1-1][c1-1]='.'; mapa[r2-1][c2-1]='K'; } |
English