public int MakeMove(Move m) { MovesHistory.Add(new Tuple <Move, int, Point>(m, Turn.GetPlyCounter(), Turn.GetPreviouslyMovedPiece())); if (m.FromPiece == Const.FLAGSHIP) //Flagship has been moved --> Update flagship position { FlagshipPosition = m.To; } else if (m.ToPiece == Const.FLAGSHIP) //Flagship has been captured --> Set flagship as out of the board { FlagshipPosition = new Point(-1, -1); } //Make move Board.Grid[m.To.X, m.To.Y] = Board.Grid[m.From.X, m.From.Y]; Board.Grid[m.From.X, m.From.Y] = 0; Turn.PlayerMoved(m); CleanLegalMoves(); if (Terminal()) { Winner = Utils.Utils.PieceToColor(MovesHistory.Last().Item1.FromPiece) == Color.Gold ? Color.Gold : Color.Silver; GameStatus = Const.GAME_OVER; } return(0); }
public void SimulateMove(Move m) { MovesHistory.Add(new Tuple <Move, int, Point>(m, Turn.GetPlyCounter(), Turn.GetPreviouslyMovedPiece())); Board.Grid[m.To.X, m.To.Y] = Board.Grid[m.From.X, m.From.Y]; Board.Grid[m.From.X, m.From.Y] = 0; Turn.PlayerMoved(m); if (m.FromPiece == Const.FLAGSHIP) //Flagship has been moved --> Update flagship position { FlagshipPosition = m.To; } else if (m.ToPiece == Const.FLAGSHIP) //Flagship has been captured --> Set flagship as out of the board { FlagshipPosition = new Point(-1, -1); } CleanLegalMoves(); }
public void Play(TimeSpan maxTime) { while (true) { if (!GameState.GetAvailableMoves(true).Any()) { break; } var move = WhiteAgent.GetMove(maxTime); GameState.MakeMove(move); MovesHistory.Add(move); if (!GameState.GetAvailableMoves(false).Any()) { break; } move = BlackAgent.GetMove(maxTime); GameState.MakeMove(move); MovesHistory.Add(move); } WhiteAgent.Finalize(); BlackAgent.Finalize(); }