private ChessTable GetTableForMove(Move move) { ChessTable newTable = stateTable; newTable.SetValue(PlayerType.None, move.From.Item1, move.From.Item2); newTable.SetValue(Player, move.To.Item1, move.To.Item2); return(newTable); }
private ChessTable GetTableForMove(Move move) { ChessTable newTable = new ChessTable(); newTable.Table = stateTable.Table; newTable.SetValue(PlayerType.None, move.From.Item1, move.From.Item2); newTable.SetValue(Player, move.To.Item1, move.To.Item2); if (Player == PlayerType.Maximizing) { UpdateTable(newTable); //Console.WriteLine("new table:"); //Console.WriteLine(newTable.ToString()); } return(newTable); }
public ChessNode(ChessTable table, PlayerType playerType) { stateTable = table; winner = new Lazy <PlayerType>( () => IsFinished(), LazyThreadSafetyMode.ExecutionAndPublication); children = new Lazy <IReadOnlyList <ChessNode> >(() => GetChildren(), LazyThreadSafetyMode.ExecutionAndPublication); Player = playerType; heuristics = new Lazy <int>( () => GetHeuristics(), LazyThreadSafetyMode.ExecutionAndPublication); Opponent = playerType == PlayerType.Maximizing ? PlayerType.Minimizing : PlayerType.Maximizing; }
public ChessTable UpdateTable(ChessTable newTable) { for (int i = 0; i < ChessTable.SIZE; i++) { for (int j = 0; j < ChessTable.SIZE; j++) { if (newTable.GetValue(i, j) == 1 && Player == PlayerType.Maximizing) { int LU = newTable.GetValue(i - 1, j - 1); int L = newTable.GetValue(i, j - 1); int LD = newTable.GetValue(i + 1, j - 1); int Up = newTable.GetValue(i - 1, j); int Down = newTable.GetValue(i + 1, j); int R = newTable.GetValue(i, j + 1); int RU = newTable.GetValue(i - 1, j + 1); int RD = newTable.GetValue(i + 1, j + 1); //8 direction if ((i + j) % 2 == 0) { if (L == R && L == 2) { newTable.SetValue(PlayerType.None, i, j - 1); newTable.SetValue(PlayerType.None, i, j + 1); } if (LU == RD && LU == 2) { newTable.SetValue(PlayerType.None, i - 1, j - 1); newTable.SetValue(PlayerType.None, i + 1, j + 1); } if (Up == Down && Up == 2) { newTable.SetValue(PlayerType.None, i - 1, j); newTable.SetValue(PlayerType.None, i + 1, j); } if (LD == RU && LD == 2) { newTable.SetValue(PlayerType.None, i + 1, j - 1); newTable.SetValue(PlayerType.None, i - 1, j + 1); } } else { if (L == R && L == 2) { newTable.SetValue(PlayerType.None, i, j - 1); newTable.SetValue(PlayerType.None, i, j + 1); } if (Up == Down && Up == 2) { newTable.SetValue(PlayerType.None, i - 1, j); newTable.SetValue(PlayerType.None, i + 1, j); } } i = ChessTable.SIZE; j = ChessTable.SIZE; } } } return(newTable); }