Exemplo n.º 1
0
        public GameState()
        {
            IsPlayerTwo = false;

            PieceToMove = null;

            LastMove = null;

            BoardPositions = new Piece[8][];
            for (int i = 0; i < 8; i++)
            {
                BoardPositions[i] = new Piece[8];
                for (int j = 0; j < 8; j++)
                {
                    BoardPositions[i][j] = null;
                }
            }

            PiecePositions = new Piece[2][];
            PiecePositions[0] = new Piece[8];
            PiecePositions[1] = new Piece[8];

            for (int i = 0; i < 8; i++)
            {
                PiecePositions[0][i] = new Piece(false, new Point(i, 7), (PieceColor)i, 0);
                BoardPositions[7][i] = PiecePositions[0][i];

                PiecePositions[1][i] = new Piece(true, new Point(7 - i, 0), (PieceColor)i, 0);
                BoardPositions[0][7 - i] = PiecePositions[1][i];

            }
        }
Exemplo n.º 2
0
 public Move(GameState state, Piece piece, Point end)
 {
     _state = state;
     _piece = piece;
     _end = end;
     _start = _piece.Position;
 }
Exemplo n.º 3
0
 public SumoDazedMove(GameState state, Piece piece)
 {
     _state = state;
     _piece = piece;
     _end = _piece.Position;
     _start = _piece.Position;
 }
Exemplo n.º 4
0
        public GameState Execute()
        {
            _numPushed = 0;
            _oldPieceToMove = _state.PieceToMove;
            _oldLastMove = _state.LastMove;
            _start = _piece.Position;

            int ystep = _end.Y - _start.Y;

            _state.BoardPositions[_piece.Position.Y][_piece.Position.X] = null;
            Piece currentPiece = _piece;
            while (_state.BoardPositions[currentPiece.Position.Y + ystep][currentPiece.Position.X] != null)
            {
                Piece next = _state.BoardPositions[currentPiece.Position.Y + ystep][currentPiece.Position.X];
                _state.BoardPositions[currentPiece.Position.Y + ystep][currentPiece.Position.X] = currentPiece;
                currentPiece.Position = new Point(currentPiece.Position.X, currentPiece.Position.Y + ystep);
                currentPiece = next;
                _numPushed++;
            }

            _state.BoardPositions[currentPiece.Position.Y + ystep][currentPiece.Position.X] = currentPiece;
            currentPiece.Position = new Point(currentPiece.Position.X, currentPiece.Position.Y + ystep);

            _state.IsPlayerTwo = !_state.IsPlayerTwo;
            _state.PieceToMove = currentPiece;
            _state.LastMove = this;

            List<IMove> possible = new List<IMove>();
            possible.Add(new SumoDazedMove(_state, currentPiece));
            _state.PossibleMoves = possible;

            return _state;
        }
Exemplo n.º 5
0
        public GameState(List<Piece> ps, Piece pToMove)
        {
            List<Piece> pieces = new List<Piece>();
            Piece pieceToMove = null;
            foreach (Piece p in ps)
            {
                pieces.Add(p.Copy());
            }
            if (pToMove != null)
            {
                foreach (Piece p in pieces)
                {
                    if (p.Position.Equals(pToMove.Position))
                    {
                        pieceToMove = p;
                        break;
                    }
                }
            }

            if (pieceToMove == null)
            {
                IsPlayerTwo = false;
                PieceToMove = null;
            }
            else
            {
                IsPlayerTwo = pieceToMove.BelongsToPlayerTwo;
                PieceToMove = pieceToMove;
            }

            LastMove = null;

            BoardPositions = new Piece[8][];
            for (int i = 0; i < 8; i++)
            {
                BoardPositions[i] = new Piece[8];
                for (int j = 0; j < 8; j++)
                {
                    BoardPositions[i][j] = null;
                }
            }

            PiecePositions = new Piece[2][];
            PiecePositions[0] = new Piece[8];
            PiecePositions[1] = new Piece[8];

            foreach (Piece piece in pieces)
            {
                BoardPositions[piece.Position.Y][piece.Position.X] = piece;
                PiecePositions[piece.BelongsToPlayerTwo ? 1 : 0][(int)piece.Color] = piece;
            }
        }
Exemplo n.º 6
0
        public GameState Execute()
        {
            _oldPieceToMove = _state.PieceToMove;
            _oldLastMove = _state.LastMove;

            _state.IsPlayerTwo = !_state.IsPlayerTwo;
            _state.PieceToMove = _state.PiecePositions[_state.IsPlayerTwo ? 1 : 0][(int)Board.Tile[_end.Y, _end.X]];
            _state.PossibleMoves = null;
            _state.LastMove = this;

            return _state;
        }
Exemplo n.º 7
0
        public GamePlayViewModel(GameEngine engine)
        {
            _engine = engine;
            UpdateDisplayState();
            _selectedPiece = null;
            SelectTileCommand = new RelayCommand(param =>
            {
                if (engine.ActivePlayer is Human && _selectedPiece == null)
                {
                    Point chosenPoint = ParamToPoint(param);
                    if ((engine.CurrentState.PieceToMove == null && chosenPoint.Y == 7)
                        || (engine.CurrentState.PieceToMove != null && chosenPoint.Equals(engine.CurrentState.PieceToMove.Position)))
                    {
                        _selectedPiece = _engine.CurrentState.BoardPositions[chosenPoint.Y][chosenPoint.X];
                    }
                }
                else if (engine.ActivePlayer is Human)
                {
                    Point chosenPoint = ParamToPoint(param);
                    IMove chosenMove = null;
                    foreach (IMove move in engine.CurrentState.PossibleMoves)
                    {
                        if(move.Piece == _selectedPiece && move.End.Equals(chosenPoint))
                        {
                            chosenMove = move;
                            break;
                        }
                    }

                    if(chosenMove != null)
                    {
                        (engine.ActivePlayer as Human).ChosenMove = chosenMove;
                        (engine.ActivePlayer as Human).GotMove = true;
                        _selectedPiece = null;
                    }
                }
            }, param => { return true; });
        }
Exemplo n.º 8
0
 public SumoPushMove(GameState state, Piece piece, Point end)
 {
     _state = state;
     _piece = piece;
     _end = end;
 }