This site requires JavaScript, please enable it in your browser!
Greenfoot back
woodkami
woodkami wrote ...

2012/3/31

Quick questions

1
2
danpost danpost

2012/3/31

#
You can just change the '8's to 'getWorld().getWidth() - 1' or 'getWorld().getHeight() - 1' (depending) and it will work for any size board. I checked up on 'Go (board game)' on Wikipedia. The corners are safe and the edges are fairly safe; so, what I had prior to the most recent code post was more to the rules of the game. That is, for lines 19 through 22 above, you would use:
if (getY() > 0 &&  !getWorld().getObjectsAt(getX(), getY() - 1, Black.class).isEmpty()) threats++;
        if (getY() < getWorld().getHeight()  - 1 && !getWorld().getObjectsAt(getX(), getY() + 1, Black.class).isEmpty()) threats++;
        if (getX() > 0 && !getWorld().getObjectsAt(getX() - 1, getY(), Black.class).isEmpty()) threats++;
        if (getX() < getWorld().getWidth() - 1 && !getWorld().getObjectsAt(getX() + 1, getY(), Black.class).isEmpty()) threats++;
unless I mis-understood; as the way they were mentioned, it was not really spelled out.
You need to login to post a reply.
1
2