-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtestWolvesAndSheep.k
79 lines (79 loc) · 1.35 KB
/
testWolvesAndSheep.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
main(){
size:=5
wolves:=newBoard(size)
attacked:=newBoard(size)
seed:=(long*)malloc(sizeof(long))
*seed=1
for true{
for x:=0; x<size; x++{
for y:=0; y<size; y++{
wolves[x][y]=false
attacked[x][y]=false
}
}
for i:=0; i<size; i++{
x:=r(seed,size)
y:=r(seed,size)
for wolves[x][y]{
x=r(seed,size)
y=r(seed,size)
}
wolves[x][y]=true
for dirX:=0-1; dirX<=1; dirX++{
for dirY:=0-1; dirY<=1; dirY++{
if dirX==0 && dirY==0{
continue
}
copyX:=x
copyY:=y
for copyX>=0 && copyY>=0 && copyX<size && copyY<size{
attacked[copyX][copyY]=true
copyX=copyX+dirX
copyY=copyY+dirY
}
}
}
}
open:=0
for x:=0; x<size; x++{
for y:=0; y<size; y++{
if !attacked[x][y]{
open++
}
}
}
if open>=3{
for x:=0; x<size; x++{
for y:=0; y<size; y++{
if wolves[x][y]{
writeByte('W')
continue
}
if attacked[x][y]{
writeByte('+')
continue
}
writeByte('S')
}
writeByte(10)
}
print(*seed)
break
}
}
}
func r(long* seed,int max)int{
*seed=(*seed*5023+257)%2147483647
res:= *seed%(long)max
if res<(long)0{
return 0-(int)res
}
return (int)res
}
newBoard(int size) bool**{
board:=(bool**)malloc(size*sizeof(bool*))
for i:=0; i<size; i++{
board[i]=(bool*)malloc(size*sizeof(bool))
}
return board
}