示例#1
0
        public void UndoMove()
        {
            mBoard.UndoLastMove();
            // In one-player mode, Undo has to remove an additional move to return to the
            // human player's turn.
            if (Players == NumberOfPlayers.One)
            {
                mBoard.UndoLastMove();
            }
            PossibleMoves = new HashSet <BoardPosition>(
                from OthelloMove m in mBoard.GetPossibleMoves()
                select m.Position
                );
            var newSquares =
                from r in Enumerable.Range(0, 8)
                from c in Enumerable.Range(0, 8)
                select new BoardPosition(r, c);
            int i = 0;

            foreach (var pos in newSquares)
            {
                mSquares[i].Player = mBoard.GetPieceAtPosition(pos);
                i++;
            }

            OnPropertyChanged(nameof(BoardValue));
            OnPropertyChanged(nameof(CurrentPlayer));
            OnPropertyChanged(nameof(CanUndo));
        }
示例#2
0
 public void UndoMove()
 {
     if (CanUndo)
     {
         mBoard.UndoLastMove();
         // In one-player mode, Undo has to remove an additional move to return to the
         // human player's turn.
         if (Players == NumberOfPlayers.One && CanUndo)
         {
             mBoard.UndoLastMove();
         }
         RebindState();
     }
 }
 public void UndoMove()
 {
     if (CanUndo)
     {
         mBoard.UndoLastMove();
         RebindState();
     }
 }
示例#4
0
        public void UndoLastMove()
        {
            mBoard.UndoLastMove();

            PossibleMoves = new HashSet <BoardPosition>(mBoard.GetPossibleMoves().Select(m => m.Position));
            var newSquares =
                from r in Enumerable.Range(0, 8)
                from c in Enumerable.Range(0, 8)
                select new BoardPosition(r, c);
            int i = 0;

            foreach (var pos in newSquares)
            {
                mSquares[i].Player = mBoard.GetPieceAtPosition(pos);
                i++;
            }

            OnPropertyChanged(nameof(BoardValue));
            OnPropertyChanged(nameof(CurrentPlayer));
            OnPropertyChanged(nameof(CanUndo));
        }
示例#5
0
        public void UndoLastMove()
        {
            var moveHistory = mBoard.MoveHistory as IReadOnlyList <OthelloMove>;

            if (moveHistory.Count() > 0)
            {
                mBoard.UndoLastMove();

                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));
            }
        }
示例#6
0
文件: Game.cs 项目: hongvt/Lectures
        static void Main(string[] args)
        {
            // The model and view for the game.
            OthelloBoard board = new OthelloBoard();
            OthelloView  view  = new OthelloView();

            while (true)
            {
                // Print the view.
                Console.WriteLine();
                Console.WriteLine();
                view.PrintView(Console.Out, board);
                Console.WriteLine();
                Console.WriteLine();

                // Print the possible moves.
                var possMoves = board.GetPossibleMoves();
                Console.WriteLine("Possible moves:");
                Console.WriteLine(String.Join(", ", possMoves));

                // Print the turn indication.
                Console.WriteLine();
                Console.Write("{0}'s turn: ", view.GetPlayerString(board.CurrentPlayer));

                // Parse user input and apply their command.
                string input = Console.ReadLine();
                if (input.StartsWith("move "))
                {
                    // Parse the move and validate that it is one of the possible moves before applying it.
                    OthelloMove move      = view.ParseMove(input.Substring(5));
                    bool        foundMove = false;
                    foreach (var poss in possMoves)
                    {
                        if (poss.Equals(move))
                        {
                            board.ApplyMove(poss);
                            foundMove = true;
                            break;
                        }
                    }
                    if (!foundMove)
                    {
                        Console.WriteLine("That is not a possible move, please try again.");
                    }
                }
                else if (input.StartsWith("undo "))
                {
                    // Parse the number of moves to undo and repeatedly undo one move.
                    int undoCount = Convert.ToInt32(input.Substring(5));
                    while (undoCount > 0 && board.MoveHistory.Count > 0)
                    {
                        board.UndoLastMove();
                        undoCount--;
                    }
                }
                else if (input == "showHistory")
                {
                    // Show the move history in reverse order.
                    Console.WriteLine("History:");
                    bool playerIsBlack = board.CurrentPlayer != 1;
                    // if board.CurrentPlayer == 1, then black is CURRENT player, not the most recent player.

                    foreach (var move in board.MoveHistory.Reverse())
                    {
                        Console.WriteLine("{0}: {1}", move.Player == 1 ? "Black" : "White", move);
                    }
                }
                else if (input == "showAdvantage")
                {
                    Console.WriteLine("Advantage: {0} in favor of {1}",
                                      board.CurrentAdvantage.Advantage,
                                      board.CurrentAdvantage.Player == 1 ? "Black" : "White");
                }
            }
        }
 public void UndoLastMove()
 {
     mBoard.UndoLastMove();
     UpdateSquares();
     UpdateBoardState();
 }