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
/*
 * OSA
 * Autor: Szymon Tur
 */

#include "osalib.h"

int ** b;
int osady, loso, x, y, kk;
bool ** visited;

void dp(int r, int c)
{
	visited[r][c] = true;
	if (b[r][c] == 1) ++loso;
	else if (b[r][c] == -1) return;
	
	if (r+1<x && !visited[r+1][c]) dp(r+1,c);
	if (r-1>=0 && !visited[r-1][c]) dp(r-1,c);
	if (c+1<y && !visited[r][c+1]) dp(r,c+1);
	if (c-1>=0 && !visited[r][c-1]) dp(r,c-1);
}

void NowaWyspa(int n, int m, char **Board)
{
	osady=0;
	x=n;
	y=m;
	b = new int * [n];
	visited = new bool * [n];
	for (int i=0;i<n;i++) 
	{
		b[i] = new int [m];
		visited[i] = new bool [m];
	}
	for (int i=0;i<n;i++)
		for (int j=0;j<m;j++)
			switch (Board[i][j])
			{
			case '.': b[i][j] = 0; break;
			case 'W': b[i][j] = -1; break;
			case 'K': b[i][j] = 1; ++osady; kk = 1000*i+j; break;
			}
}
int NowaWarownia(int r, int c)
{
	loso = 0;
	b[r-1][c-1] = -1;
	for (int i=0;i<x;i++)
		for (int j=0;j<y;j++) visited[i][j] = false;
	dp(kk/1000,kk%1000);
	if (loso < osady)
	{
		b[r-1][c-1] = 0;
		return 0;
	}
	else return 1;
}
void PrzeniesOsade(int r1, int c1, int r2, int c2)
{
	b[r1-1][c1-1] = 0;
	b[r2-1][c2-1] = 1;
	if (kk==1000*r1+c1-1001) kk = 1000*r2+c2-1001;
}