去模拟 - 标记死石 [英] Go Simulation - Mark dead stones

查看:70
本文介绍了去模拟 - 标记死石的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hiya,我正在尝试创建一个 Go (游戏) )在PHP中模拟,问题是如何标记死石。


每块石头都有一些自由,附近是空旷的地方,当一组石头被完全封闭在另一种颜色的石头中时,已经死了。


这里是我迄今为止所做的例子:
http://www.k4s.ch/test/sca/test.php


p =播放器[1:黑色,2:白色]

x,y = [移动坐标]

& reset to wipe


我们可以在石头附近有4件事,让'' s说黑色(1):

- 另一种相同颜色的石头(1)

- 另一种颜色的另一种石头(2)

- 没有(在板外,即在边界上)

- 一个空的空间(标记为0)


'这就是我想要做的事情......例如每次我放一块新石头:


[PHP]

功能检查($ x,$ y){

// $ array是一个包含所有st和st的地方的数组一个即。 [4] [5] = 2,[4] [6] = 1,..

全球$数组;

// $我是玩家1或2

$ me = $ array [$ x] [$ y];

// $ near是一个包含北,南,东,西石头的阵列(如果有的话) )

$ 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 ++){

//我怎么能重新执行下一块石头的功能相同吗?

if(($ near [$ a]!== $ me)&&($ near [$ a]!== 0)&&(isset($ near [$ a)))){OMG有一块敌人的石头!让我们看看它是否有一些自由......否则它已经死了! }

}

}

[/ PHP]


就是这样......希望有人能理解我在说什么:P


最后一块石头有多少自由并不重要..重要的是靠近那块石头的石头(因为如果它'自由它死了)O_o


(对不起英语不好意思)

解决方案

x,

y){

//


数组是一个包含所有地方的数组,即。 [4] [5] = 2,[4] [6] = 1,..

global


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:
http://www.k4s.ch/test/sca/test.php

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)

解决方案

x,


y) {
//


array is an array with all the places with some stone ie. [4][5] = 2, [4][6] = 1, ..
global


这篇关于去模拟 - 标记死石的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆