/******** * Add a new child based on moving the pawn from (x1, y1) to (x2, y2) */ public void AddChild(int x1, int y1, int x2, int y2, List <Board> children, FujisanMoveType moveType) { Board board = Clone(x1, y1, x2, y2, length); board.pawns[x1, y1] = 0; board.pawns[x2, y2] = 1; board.moveType = moveType; board.countermoves = this.countermoves; if (this.Heuristic2() < board.Heuristic2()) { board.countermoves++; } children.Add(board); }
/****** * Creates a random starting board state */ public Board(Random random, FujisanSetup s) { this.random = random; move = "START"; moveType = FujisanMoveType.START; values = new int[2, 14]; if (s == FujisanSetup.ENGRAVED) { // Make the 20 tiles matching domino distribution List <Tile> list = new List <Tile>(); for (int i = 0; i < 6; i++) { int start = i; if (i == 0) { start = 1; } for (int j = start; j < 6; j++) { list.Add(new Tile(i, j)); } } //Console.WriteLine("AUGH!!!!" + list.Count); Shuffle <Tile>(list, random); // Fill in numbers on the left half int t = -1; for (int i = 0; i < 5; i++) { t++; if (random.NextDouble() > 0.5) { list[t].Rotate(); } values[0, t + 1] = list[t].values[0, 0]; values[1, t + 1] = list[t].values[1, 0]; } values[0, t + 2] = list[t].values[0, 1]; values[1, t + 2] = list[t].values[1, 1]; // Fill in numbers on the right half for (int i = 0; i < 5; i++) { t++; if (random.NextDouble() > 0.5) { list[t].Rotate(); } values[0, 12 - i] = list[t].values[0, 1]; values[1, 12 - i] = list[t].values[1, 1]; } values[0, 7] = list[t].values[0, 0]; values[1, 7] = list[t].values[1, 0]; } else if (s == FujisanSetup.DOMINO) { // Make the 15 tiles matching domino distribution List <Tile> list = new List <Tile>(); for (int i = 0; i < 6; i++) { int start = i + 1; for (int j = start; j < 6; j++) { list.Add(new Tile(i, j)); } } //Console.WriteLine("AUGH!!!!" + list.Count); Shuffle <Tile>(list, random); // Fill in numbers on the left half int t = -1; for (int i = 0; i < 6; i++) { t++; if (random.NextDouble() > 0.5) { list[t].Rotate(); } values[0, t + 1] = list[t].values[0, 0]; values[1, t + 1] = list[t].values[1, 0]; } // Fill in numbers on the right half for (int i = 0; i < 6; i++) { t++; if (random.NextDouble() > 0.5) { list[t].Rotate(); } values[0, 12 - i] = list[t].values[0, 1]; values[1, 12 - i] = list[t].values[1, 1]; } } else if (s == FujisanSetup.PIECEPACK) { // Make the coins for the piecepack List <Byte>[] coins = new List <Byte> [4]; for (int i = 0; i < 4; i++) { coins[i] = new List <Byte>(); } for (int i = 0; i < 6; i++) { for (int j = 0; j < 4; j++) { coins[j].Add((byte)i); } } // Shuffle the coins within each type (sun, moon, etc) for (int i = 0; i < 4; i++) { Shuffle <Byte>(coins[i], random); } // Place the coins on the board, starting at the // right, and filling two from each type at a time int where = 12; for (int k = 0; k < 3; k++) { for (int i = 0; i < 4; i++) { for (int j = 0; j < 2; j++) { values[j, where] = coins[i][j + k * 2]; } where--; } } } else if (s == FujisanSetup.ANYCOIN) { // Make the coins for the piecepack List <Byte> coins = new List <Byte>(); for (int i = 0; i < 6; i++) { for (int j = 0; j < 4; j++) { coins.Add((byte)i); } } // Shuffle the coins Shuffle <Byte>(coins, random); // Place the coins on the board, starting at the // right, and filling two from each type at a time int where = 12; for (int k = 0; k < 12; k++) { for (int j = 0; j < 2; j++) { values[j, where] = coins[j + k * 2]; } where--; } } else if (s == FujisanSetup.HARDCODE) { // Initial board from Puzzle Four // http://www.ludism.org/ppwiki/Fuji-san#Heading9 values[0, 12] = 5; values[1, 12] = 4; values[0, 11] = 3; values[1, 11] = 5; values[0, 10] = 3; values[1, 10] = 0; values[0, 9] = 4; values[1, 9] = 1; values[0, 8] = 2; values[1, 8] = 0; values[0, 7] = 2; values[1, 7] = 0; values[0, 6] = 2; values[1, 6] = 1; values[0, 5] = 0; values[1, 5] = 3; values[0, 4] = 1; values[1, 4] = 3; values[0, 3] = 1; values[1, 3] = 4; values[0, 2] = 5; values[1, 2] = 4; values[0, 1] = 5; values[1, 1] = 2; } else if (s == FujisanSetup.RANDOM) { for (int i = 0; i < 2; i++) { for (int j = 1; j < 13; j++) { values[i, j] = random.Next(0, 6); } } } // Place the pawns on the edges of the board pawns = new int[2, 14]; pawns[0, 0] = 1; pawns[1, 0] = 1; pawns[0, 13] = 1; pawns[1, 13] = 1; }