Example #1
0
 public WaitingForPlayerMoveState(IPhutballBoard phutballBoard, MovesHistory movesHistory, IPlayersState playersState)
 {
     _phutballBoard = phutballBoard;
     _movesHistory  = movesHistory;
     _playersState  = playersState;
     _performMoves  = new PerformMoves(phutballBoard, playersState);
 }
Example #2
0
        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);
        }
Example #3
0
 public BestMoveApplier(IMoveFinders moveFinders, MovesHistory movesHistory, IFieldsGraph fieldsGraph, IPerformMoves performMoves, IEventPublisher eventPublisher)
 {
     _moveFinders    = moveFinders;
     _eventPublisher = eventPublisher;
     _performMoves   = performMoves;
     _movesHistory   = movesHistory;
     _fieldsGraph    = fieldsGraph;
 }
Example #4
0
 public PlayerSelectedFieldStateMove(
     IPhutballBoard phutballBoard,
     IPlayersState playersState,
     Field selectedField,
     MovesHistory movesHistory)
 {
     _phutballBoard = phutballBoard;
     _movesHistory  = movesHistory;
     _playersState  = playersState;
     _performMoves  = new PerformMoves(phutballBoard, _playersState);
     _selectedField = selectedField;
 }
Example #5
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();
        }
Example #6
0
 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();
 }
Example #7
0
        public void UndoMove(Move m)
        {
            Board.Grid[m.From.X, m.From.Y] = m.FromPiece;
            Board.Grid[m.To.X, m.To.Y]     = m.ToPiece;

            Turn.PlayerUnMoved(MovesHistory.Last());

            MovesHistory.RemoveAt(MovesHistory.Count - 1);
            //Turn.SetPreviousPieceMoved(MovesHistory.Last().Item3);


            if (m.FromPiece == Const.FLAGSHIP)
            {
                FlagshipPosition = m.From;
            }
            else if (m.ToPiece == Const.FLAGSHIP)
            {
                FlagshipPosition = m.To;
            }

            CleanLegalMoves();
        }
Example #8
0
 public MovesHistoryPresenter(MovesHistory movesHistory, IEventPublisher eventPublisher)
 {
     _movesHistory   = movesHistory;
     _eventPublisher = eventPublisher;
     _eventPublisher.Subscribe <MovesHistoryChanged>(OnMovesHistoryChanged);
 }
Example #9
0
        public GameUI()
        {
            game = new Game();

            GameHistory = new MovesHistory();
        }