Hiya, i'm trying to create a Go (the game) simulation in PHP, the problem is how to mark dead stones.
each stone has some liberties wich are the empty territories nearby, when a group of stones is completly enclosed in stones of another color, is dead.
here the example of what i've done so far:
p= player [1: black, 2: white]
x,y = [move coordinates]
&reset to wipe
We can have 4 things near a stone, let's say im black (1):
- another stone of the same color (1)
- another stone of another color (2)
- nothing (out of the board, ie. on the border)
- an empty space (marked as '0')
that's what i was thinking to do.. for instance each time i place a new stone:
[PHP]
function check($x,$y) {
//$array is an array with all the places with some stone ie. [4][5] = 2, [4][6] = 1, ..
global $array;
//$me is the player 1 or 2
$me = $array[$x][$y];
//$near is an array with the north, south, east, west stones (if any)
$near[0] = $array[$x][$y-1];
$near[1] = $array[$x+1][$y];
$near[2] = $array[$x][$y+1];
$near[3] = $array[$x-1][$y];
for ($a=0;$a<=3;$a+ +) {
//how can i re-exec the same function to the next stone ?
if (($near[$a] !== $me) && ($near[$a] !== 0) && (isset($near[$a]))) { OMG there is an enemy stone ! let's see if it has some liberty.. otherwise it's dead! }
}
}
[/PHP]
That's it.. hopefully someone will understand what im talking about :P
In the end how many liberties a stone has is not important.. the important thing is the stone near that one (because if it ain't liberties it dies) O_o
(sorry for the bad english lol)
each stone has some liberties wich are the empty territories nearby, when a group of stones is completly enclosed in stones of another color, is dead.
here the example of what i've done so far:
p= player [1: black, 2: white]
x,y = [move coordinates]
&reset to wipe
We can have 4 things near a stone, let's say im black (1):
- another stone of the same color (1)
- another stone of another color (2)
- nothing (out of the board, ie. on the border)
- an empty space (marked as '0')
that's what i was thinking to do.. for instance each time i place a new stone:
[PHP]
function check($x,$y) {
//$array is an array with all the places with some stone ie. [4][5] = 2, [4][6] = 1, ..
global $array;
//$me is the player 1 or 2
$me = $array[$x][$y];
//$near is an array with the north, south, east, west stones (if any)
$near[0] = $array[$x][$y-1];
$near[1] = $array[$x+1][$y];
$near[2] = $array[$x][$y+1];
$near[3] = $array[$x-1][$y];
for ($a=0;$a<=3;$a+ +) {
//how can i re-exec the same function to the next stone ?
if (($near[$a] !== $me) && ($near[$a] !== 0) && (isset($near[$a]))) { OMG there is an enemy stone ! let's see if it has some liberty.. otherwise it's dead! }
}
}
[/PHP]
That's it.. hopefully someone will understand what im talking about :P
In the end how many liberties a stone has is not important.. the important thing is the stone near that one (because if it ain't liberties it dies) O_o
(sorry for the bad english lol)
Comment