public GameBoard(int size) { if (size < 3 || size > 8) { throw new TakException("Minimum board size is 3. Maximum board size is 8."); } turn = Colour.White; this.size = size; stacks = new StoneStack[size, size]; state = GameState.InProgress; whiteStones = new StoneReserve(size); blackStones = new StoneReserve(size); for (int x = 0; x < size; x++) { for (int y = 0; y < size; y++) { stacks[x, y] = new StoneStack(); } } }
public StoneStack PickUpStack(int x, int y, int amount = UNSPECIFIED) { if (!ValidIndex(x, y)) { throw new IllegalMoveException("\nIndex [" + x + ", " + y + "] is out of bounds"); } if (stacks[x, y].Count < 1) { throw new IllegalMoveException("\nStack is empty."); } if (!CurrentPlayerIsOwner(x, y)) { throw new IllegalMoveException("\nCurrent player does not control the stack at [" + x + ", " + y + "]."); } if (amount == UNSPECIFIED) { if (stacks[x, y].Count > 1) { throw new IllegalMoveException("\nUnspecified number of stones to pick up, but stack contains more than one"); } else { amount = 1; } } if (amount > size) { throw new IllegalMoveException("\nCould not pick up " + amount + " stones, the size of the gameboard is " + size); } StoneStack pickedUp = stacks[x, y].Separate(amount); return(pickedUp); }