public static void AddRightDiagonal(ChessBoard chessBoard) { var levels = RandomGenerator.GetDistinctInts(4, 1, 16); chessBoard.AddNew(new Position(0, 3), levels[0]); chessBoard.AddNew(new Position(1, 2), levels[1]); chessBoard.AddNew(new Position(2, 1), levels[2]); chessBoard.AddNew(new Position(3, 0), levels[3]); }
public void TestBottomLineMoveDownFail() { var chessBoard = new ChessBoard(); chessBoard.AddNew(new Position(3, 0), ChessBoardHandler.RandomLevel()); chessBoard.AddNew(new Position(3, 1), ChessBoardHandler.RandomLevel()); chessBoard.AddNew(new Position(3, 2), ChessBoardHandler.RandomLevel()); chessBoard.AddNew(new Position(3, 3), ChessBoardHandler.RandomLevel()); Assert.AreEqual(chessBoard.Move(Direction.Down), false); }
public void TestRightLineMoveRightFail() { var chessBoard = new ChessBoard(); chessBoard.AddNew(new Position(0, 3), ChessBoardHandler.RandomLevel()); chessBoard.AddNew(new Position(1, 3), ChessBoardHandler.RandomLevel()); chessBoard.AddNew(new Position(2, 3), ChessBoardHandler.RandomLevel()); chessBoard.AddNew(new Position(3, 3), ChessBoardHandler.RandomLevel()); Assert.AreEqual(chessBoard.Move(Direction.Right), false); }
public void TestLeftLineMoveLeftFail() { var chessBoard = new ChessBoard(); chessBoard.AddNew(new Position(0, 0), ChessBoardHandler.RandomLevel()); chessBoard.AddNew(new Position(1, 0), ChessBoardHandler.RandomLevel()); chessBoard.AddNew(new Position(2, 0), ChessBoardHandler.RandomLevel()); chessBoard.AddNew(new Position(3, 0), ChessBoardHandler.RandomLevel()); Assert.AreEqual(chessBoard.Move(Direction.Left), false); }
public void TestToplLineMoveUpFail() { var chessBoard = new ChessBoard(); chessBoard.AddNew(new Position(0, 0), ChessBoardHandler.RandomLevel()); chessBoard.AddNew(new Position(0, 1), ChessBoardHandler.RandomLevel()); chessBoard.AddNew(new Position(0, 2), ChessBoardHandler.RandomLevel()); chessBoard.AddNew(new Position(0, 3), ChessBoardHandler.RandomLevel()); Assert.AreEqual(chessBoard.Move(Direction.Up), false); }
public void SingleRandomAddTheSamePlaceTest() { var chessBoard = new ChessBoard(); int randomRow = RandomGenerator.Next(4); int randomCol = RandomGenerator.Next(4); var randomPosition = new Position(randomRow, randomCol); chessBoard.AddNew(randomPosition, ChessBoardHandler.RandomLevel()); chessBoard.AddNew(randomPosition, ChessBoardHandler.RandomLevel()); Assert.AreEqual(chessBoard.EmptyCount, 15); }
public static void AddSymmetryToRightDiagonal(ChessBoard chessBoard) { var oneSideCount = RandomGenerator.Next(1, 6); var levels = RandomGenerator.GetDistinctInts(oneSideCount, 1, 16); var emptyPositions = chessBoard.GetEmptyPositions(); int occupyCount = Math.Min(oneSideCount, chessBoard.EmptyCount / 2); for (int i = 0; i < occupyCount; ++i) { var position = emptyPositions[i]; chessBoard.AddNew(position, levels[i]); chessBoard.AddNew(new Position(3 - position.Col, 3 - position.Row), levels[i]); } }
public void TestLineMoveUpMergeOnce() { for (int col = 0; col < 4; ++col) { var chessBoard = new ChessBoard(); int level = ChessBoardHandler.RandomLevel(); var rows = RandomGenerator.GetDistinctInts(2, 4); chessBoard.AddNew(new Position(rows[0], col), level); chessBoard.AddNew(new Position(rows[1], col), level); Assert.AreEqual(chessBoard.Move(Direction.Up), true); Assert.AreEqual(chessBoard.EmptyCount, 15); } }
public void TestLineMoveUpSuccess() { for (int col = 0; col < 4; ++col) { var chessBoard = new ChessBoard(); var levels = RandomGenerator.GetDistinctInts(2, 1, 16); var rows = RandomGenerator.GetDistinctInts(2, 1, 4); chessBoard.AddNew(new Position(rows[0], col), levels[0]); chessBoard.AddNew(new Position(rows[1], col), levels[1]); Assert.AreEqual(chessBoard.Move(Direction.Up), true); Assert.AreEqual(chessBoard.EmptyCount, 14); } }
public void TestLineMoveRightMergeOnce() { for (int row = 0; row < 4; ++row) { var chessBoard = new ChessBoard(); int level = ChessBoardHandler.RandomLevel(); var cols = RandomGenerator.GetDistinctInts(2, 4); chessBoard.AddNew(new Position(row, cols[0]), level); chessBoard.AddNew(new Position(row, cols[1]), level); Assert.AreEqual(chessBoard.Move(Direction.Right), true); Assert.AreEqual(chessBoard.EmptyCount, 15); } }
public void TestMoveRightOneDistinctLineFail() { for (int row = 0; row < 4; ++row) { var chessBoard = new ChessBoard(); var levels = ChessBoardHandler.GetRandomDistinctLevels(4); chessBoard.AddNew(new Position(row, 0), levels[0]); chessBoard.AddNew(new Position(row, 1), levels[1]); chessBoard.AddNew(new Position(row, 2), levels[2]); chessBoard.AddNew(new Position(row, 3), levels[3]); Assert.AreEqual(chessBoard.Move(Direction.Right), false); } }
public void TestDistinctLineMoveUpFail() { for (int col = 0; col < 4; ++col) { var chessBoard = new ChessBoard(); var levels = RandomGenerator.GetDistinctInts(4, 1, 16); chessBoard.AddNew(new Position(0, col), levels[0]); chessBoard.AddNew(new Position(1, col), levels[1]); chessBoard.AddNew(new Position(2, col), levels[2]); chessBoard.AddNew(new Position(3, col), levels[3]); Assert.AreEqual(chessBoard.Move(Direction.Up), false); } }
public void TestDistinctLineMoveDownFail() { for (int col = 0; col < 4; ++col) { var chessBoard = new ChessBoard(); var levels = ChessBoardHandler.GetRandomDistinctLevels(4); chessBoard.AddNew(new Position(0, col), levels[0]); chessBoard.AddNew(new Position(1, col), levels[1]); chessBoard.AddNew(new Position(2, col), levels[2]); chessBoard.AddNew(new Position(3, col), levels[3]); Assert.AreEqual(chessBoard.Move(Direction.Down), false); } }
public void TestLineMoveRightSuccess() { for (int row = 0; row < 4; ++row) { var chessBoard = new ChessBoard(); var levels = ChessBoardHandler.GetRandomDistinctLevels(2); var cols = RandomGenerator.GetDistinctInts(2, 0, 3); chessBoard.AddNew(new Position(row, cols[0]), levels[0]); chessBoard.AddNew(new Position(row, cols[1]), levels[1]); Assert.AreEqual(chessBoard.Move(Direction.Right), true); Assert.AreEqual(chessBoard.EmptyCount, 14); } }
public void TransposeRightTest() { for (int i = 0; i < 100; ++i) { var chessBoard = new ChessBoard(); ChessBoardHandler.AddRightDiagonal(chessBoard); chessBoard.AddNew(new Position(0, 0), 10); chessBoard.AddNew(new Position(3, 3), 10); Assert.AreEqual(chessBoard, chessBoard.ToTransposeRight()); chessBoard.RandomAdd(); Assert.AreNotEqual(chessBoard, chessBoard.ToTransposeRight()); Assert.AreEqual(Evaluator.EvalForMove(chessBoard), Evaluator.EvalForMove(chessBoard.ToTransposeRight()), 0.01); Assert.AreEqual(Evaluator.EvalForAdd(chessBoard), Evaluator.EvalForAdd(chessBoard.ToTransposeRight()), 0.01); } }
public void TestLineMoveLeftMergeTwice() { for (int i = 0; i < 4; ++i) { var chessBoard = new ChessBoard(); var levels = ChessBoardHandler.GetRandomDistinctLevels(2); chessBoard.AddNew(new Position(i, 0), levels[0]); chessBoard.AddNew(new Position(i, 1), levels[0]); chessBoard.AddNew(new Position(i, 2), levels[1]); chessBoard.AddNew(new Position(i, 3), levels[1]); Assert.AreEqual(chessBoard.Move(Direction.Left), true); Assert.AreEqual(chessBoard.EmptyCount, 14); } }
public void TestLineMoveRightMergeTwice() { for (int row = 0; row < 4; ++row) { var chessBoard = new ChessBoard(); var levels = ChessBoardHandler.GetRandomDistinctLevels(2); chessBoard.AddNew(new Position(row, 0), levels[0]); chessBoard.AddNew(new Position(row, 1), levels[0]); chessBoard.AddNew(new Position(row, 2), levels[1]); chessBoard.AddNew(new Position(row, 3), levels[1]); Assert.AreEqual(chessBoard.Move(Direction.Right), true); Assert.AreEqual(chessBoard.EmptyCount, 14); } }
public void TestLineMoveUpMergeTwice() { for (int col = 0; col < 4; ++col) { var chessBoard = new ChessBoard(); var levels = ChessBoardHandler.GetRandomDistinctLevels(2); chessBoard.AddNew(new Position(0, col), levels[0]); chessBoard.AddNew(new Position(1, col), levels[0]); chessBoard.AddNew(new Position(2, col), levels[1]); chessBoard.AddNew(new Position(3, col), levels[1]); Assert.AreEqual(chessBoard.Move(Direction.Up), true); Assert.AreEqual(chessBoard.EmptyCount, 14); } }
private void ChooseAnnoyingChess(ChessBoard chessBoard) { this[AddLevels[0]] = new List <Position>(); this[AddLevels[1]] = new List <Position>(); var emptyPositions = chessBoard.GetEmptyPositions(); foreach (int level in AddLevels) { foreach (var position in emptyPositions) { chessBoard.AddNew(position, level); double eval = Evaluator.EvalForAdd(chessBoard); if (eval < minEval) { minEval = eval; this[AddLevels[0]].Clear(); this[AddLevels[1]].Clear(); } if (eval == minEval) { this[level].Add(position); } chessBoard.SetEmpty(position); } } }
public static void RandomAddLevelOne(ChessBoard chessBoard, int count) { var emptyPositions = chessBoard.GetEmptyPositions(); int occupyCount = Math.Min(count, chessBoard.EmptyCount); var levels = RandomGenerator.GetDistinctInts(occupyCount, 1, 16); for (int i = 0; i < occupyCount; ++i) { chessBoard.AddNew(emptyPositions[i], levels[i]); } }
public double MoveStateEvaluation(ChessBoard newBoard, int depth) { if (depth == 0) { return(Evaluator.EvalForMove(newBoard)); } double result = Evaluator.EvalForMove(newBoard); var emptyPositions = newBoard.GetEmptyPositions(); foreach (int level in addLevels) { foreach (var position in emptyPositions) { newBoard.AddNew(position, addLevels[0]); result += AddStateEvaluation(newBoard, depth - 1) * (1 - levelTwoPossibility); newBoard.AddNew(position, addLevels[1]); result += AddStateEvaluation(newBoard, depth - 1) * levelTwoPossibility; newBoard.SetEmpty(position); } } return(result); }
public void RandomAddNewSetEmptyTest() { var addEmptyBoard = new ChessBoard(); var emptyPositions = addEmptyBoard.GetEmptyPositions(); int occupyCount = RandomGenerator.Next(emptyPositions.Count); for (int i = 0; i < occupyCount; ++i) { addEmptyBoard.AddNew(emptyPositions[i], ChessBoardHandler.RandomLevel()); addEmptyBoard.SetEmpty(emptyPositions[i]); } var emptyBoard = new ChessBoard(); Assert.AreEqual(addEmptyBoard.EmptyCount, 16); Assert.AreEqual(addEmptyBoard, emptyBoard); }
public static void SingleDifferentAddSetEmptyTest() { var chessBoard = new ChessBoard(); var newBoard = new ChessBoard(chessBoard); var emptyPositions = chessBoard.GetEmptyPositions(); var emptyIndices = RandomGenerator.GetDistinctInts(2, chessBoard.EmptyCount); chessBoard.AddNew(emptyPositions[emptyIndices[0]], 2); var addedBoard = new ChessBoard(chessBoard); chessBoard.SetEmpty(emptyPositions[emptyIndices[1]]); Assert.AreEqual(chessBoard.EmptyCount, 15); Assert.AreNotEqual(chessBoard, newBoard); Assert.AreEqual(addedBoard, chessBoard); }
public void AllAddNewSetEmptyTest() { var addEmptyBoard = new ChessBoard(); var emptyBoard = new ChessBoard(); for (int row = 0; row < 4; ++row) { for (int col = 0; col < 4; ++col) { addEmptyBoard.AddNew(new Position(row, col), 1); addEmptyBoard.SetEmpty(new Position(row, col)); Assert.AreEqual(addEmptyBoard, emptyBoard); Console.WriteLine("{0}\t{1}", row, col); } } }
public void TestDistinctCount() { var chessBoard = new ChessBoard(); var levels = ChessBoardHandler.GetRandomCountDistinctLevels(); int levelIndex = 0; for (int row = 0; row < 4; ++row) { for (int col = 0; col < 4; ++col) { if (levelIndex == levels.Length) { break; } chessBoard.AddNew(new Position(row, col), levels[levelIndex]); ++levelIndex; } } Assert.AreEqual(chessBoard.DistinctCount, levels.Length); }
public double AddSearch(int depth, double alpha, double beta) { int hashFlag = HashAlpha; double val; if ((val = ProbeHash(depth, alpha, beta, out var prevDecision)) != Infinity) { ++curOff; return(val); } if (depth == 0) { val = -Evaluator.EvalForMove(chessBoard); RecordHash(depth, val, HashExact, prevDecision); return(val); } var addPositions = SortedPositions(prevDecision); foreach (var position in addPositions) { foreach (int level in addLevels) { chessBoard.AddNew(position, level); val = -MoveSearch(depth - 1, -beta, -alpha); chessBoard.SetEmpty(position); if (val >= beta) { RecordHash(depth, beta, HashBeta, prevDecision); return(beta); } if (val > alpha) { hashFlag = HashExact; prevDecision.bestPosition = position; alpha = val; } } } RecordHash(depth, alpha, hashFlag, prevDecision); return(alpha); }
public ChessBoard GetTestBoard2() { var chessBoard = new ChessBoard(); chessBoard.AddNew(new Position(0, 0), 0); chessBoard.AddNew(new Position(0, 1), 0); chessBoard.AddNew(new Position(0, 2), 0); chessBoard.AddNew(new Position(0, 3), 0); chessBoard.AddNew(new Position(1, 0), 2); chessBoard.AddNew(new Position(1, 1), 0); chessBoard.AddNew(new Position(1, 2), 1); chessBoard.AddNew(new Position(1, 3), 0); chessBoard.AddNew(new Position(2, 0), 3); chessBoard.AddNew(new Position(2, 1), 3); chessBoard.AddNew(new Position(2, 2), 2); chessBoard.AddNew(new Position(2, 3), 0); chessBoard.AddNew(new Position(3, 0), 11); chessBoard.AddNew(new Position(3, 1), 8); chessBoard.AddNew(new Position(3, 2), 3); chessBoard.AddNew(new Position(3, 3), 0); return(chessBoard); }