Search

Tuesday, August 21, 2012

Day 13: Groups



It's time for the engine to recognize groups!

A little thing I saw as I was coding this: The size of the board and the moves it have should be part of the board class. So, I am changing all the "size" coming from the main loop, and the methods that received the whole board array.
First thing I made is an arraylist that have all the positions of the group. Then I followed this logic:


  1. Create a pointer variable with value 0, this variable is simply an integer that have the value of the last visited element of the arraylist.
  2. Start a while loop, all what happens now will be done until I reach the end of the array.
  3. Search the position to the left in the board, if it have the same value as the first element it adds the position to the arraylist (if it is not in the arraylist yet).
  4. Search the position to the right in the board, if it have the same value as the first element it adds the position to the arraylist (if it is not in the arraylist yet).
  5. Search the position up in the board, if it have the same value as the first element it adds the position to the arraylist (if it is not in the arraylist yet).
  6. Search the position down in the board, if it have the same value as the first element it adds the position to the arraylist (if it is not in the arraylist yet).
  7. If the pointer is = to the arraylist size of the arraylist, then all the group was found, so it should exit from the loop.
  8. If the pointer < to the arraylist size, then increase the pointer by one.
  9. When exits the loop return the arraylist.
After a lot of problems implementing this, I have some code:



I also made a method in Console to show the groups and a method in the engine that gets the groups.

Next step: Liberties.

No comments:

Post a Comment