Search

Thursday, August 23, 2012

Day 15: KO. Part I



This is starting to get hard... And I know that this will be a lot harder...


Definition of KO

The program now can see groups, liberties, kill stones, etc. I think I am able to program the rule of ko. But, what is ko? Let's see...


  According to KGS:
The ko rule says that you can never make a capture that brings the board right back to where it was before

 Here is a little example:


Here, black and white can retake a stone forever, if there is no ko rule. So, if black takes a stone, white should wait a turn to recapture.

Ideas to implement KO

First thing I notice, this is about repetition of positions, so a copy of the board for the last move of every color should be saved. Then if there is a capture of a stone a ko method should be activated to see if there is a move that repeats the saved board.

So, once this method is created it should be something like this:

  1. x plays.
  2. The board for x is saved.
  3. y plays and captures
  4. The board for y is saved.
  5. The program looks at all the possible moves (positions where value==0).
  6. the program verifies that playing a move doesn't repeat the board for x.
  7. If that returns false the move is kept in possible moves, else it is discarded.
  8. 6 and 7 are repeated for all the possible moves.
  9. An array with all the possible moves is returned.
In the next post... CODING!

2 comments:

  1. You don't need to keep a copy of the previous board to detect the simplest version of ko (board repetition after 2 moves). This can only happen (a) if the current move captures EXACTLY ONE stone. But this is not quite enough. (b) That one stone must have been played on the previous move. We're almost there now. (c) The previous move must ALSO have captured exactly one stone.
    If a, b, and c are true, the simple version of ko has occurred.

    So if you keep track for the last and current move if they capture exactly one stone, you can very quickly detect ko.

    ReplyDelete
    Replies
    1. I will see how can I implement this in the structure of my program (will see if this is possible without mayor changes). Thanks a lot for your suggestion!!!!!

      Delete