コード例 #1
0
ファイル: OthelloViewModel.cs プロジェクト: akariin/CECS475
        public void ApplyMove(BoardPosition position)
        {
            var possMoves = mBoard.GetPossibleMoves() as IEnumerable <OthelloMove>;

            foreach (var move in possMoves)
            {
                if (move.Position.Equals(position))
                {
                    mBoard.ApplyMove(move);
                    break;
                }
            }

            PossibleMoves = new HashSet <BoardPosition>(mBoard.GetPossibleMoves().Select(m => m.Position));
            var newSquares = BoardPosition.GetRectangularPositions(8, 8);
            int i          = 0;

            foreach (var pos in newSquares)
            {
                mSquares[i].Player = mBoard.GetPlayerAtPosition(pos);
                i++;
            }
            OnPropertyChanged(nameof(CurrentAdvantage));
            OnPropertyChanged(nameof(CurrentPlayer));
        }
        public void UpdateSquares()
        {
            PossibleMoves = new HashSet <BoardPosition>(mBoard.GetPossibleMoves().Select(m => m.Position));
            var newSquares = BoardPosition.GetRectangularPositions(8, 8);
            int i          = 0;

            foreach (var pos in newSquares)
            {
                mSquares[i].Player = mBoard.GetPlayerAtPosition(pos);
                i++;
            }
        }
コード例 #3
0
        public OthelloViewModel()
        {
            mBoard   = new OthelloBoard();
            mSquares = new ObservableCollection <OthelloSquare>(
                BoardPosition.GetRectangularPositions(8, 8)
                .Select(p => new OthelloSquare()
            {
                Position = p,
                Player   = mBoard.GetPlayerAtPosition(p)
            })
                );

            PossibleMoves = new HashSet <BoardPosition>(mBoard.GetPossibleMoves().Select(m => m.Position));
        }
コード例 #4
0
        public string BoardToString(OthelloBoard board)
        {
            StringBuilder str = new StringBuilder();

            str.AppendLine("- 0 1 2 3 4 5 6 7");
            for (int i = 0; i < OthelloBoard.BOARD_SIZE; i++)
            {
                str.Append(i);
                str.Append(" ");
                for (int j = 0; j < OthelloBoard.BOARD_SIZE; j++)
                {
                    int space = board.GetPlayerAtPosition(new BoardPosition(i, j));
                    str.Append(LABELS[space]);
                    str.Append(" ");
                }
                str.AppendLine();
            }
            return(str.ToString());
        }
コード例 #5
0
        public OthelloViewModel()
        {
            mBoard = new OthelloBoard();

            // Initialize the squares objects based on the board's initial state.
            mSquares = new ObservableCollection <OthelloSquare>(
                BoardPosition.GetRectangularPositions(8, 8)
                .Select(pos => new OthelloSquare()
            {
                Position = pos,
                Player   = mBoard.GetPlayerAtPosition(pos)
            })
                );

            PossibleMoves = new HashSet <BoardPosition>(
                from OthelloMove m in mBoard.GetPossibleMoves()
                select m.Position
                );
        }
コード例 #6
0
        private void RebindState()
        {
            // Rebind the possible moves, now that the board has changed.
            PossibleMoves = new HashSet <BoardPosition>(
                from OthelloMove m in mBoard.GetPossibleMoves()
                select m.Position
                );

            // Update the collection of squares by examining the new board state.
            var newSquares = BoardPosition.GetRectangularPositions(8, 8);
            int i          = 0;

            foreach (var pos in newSquares)
            {
                mSquares[i].Player = mBoard.GetPlayerAtPosition(pos);
                i++;
            }
            OnPropertyChanged(nameof(BoardAdvantage));
            OnPropertyChanged(nameof(CurrentPlayer));
            OnPropertyChanged(nameof(CanUndo));
        }