コード例 #1
0
        public ObservableBoardHistory(BoardHistory boardHistory, BoardHistory activeBoardHistory = null, Action <int> moveNumberChangedCallback = null)
        {
            _boardHistory              = boardHistory ?? throw new ArgumentNullException(nameof(boardHistory));
            _activeBoardHistory        = activeBoardHistory ?? boardHistory;
            _moveNumberChangedCallback = moveNumberChangedCallback;

            if (_activeBoardHistory.Count > _boardHistory.Count)
            {
                throw new ArgumentException("Active history has more moves than history.");
            }

            int countWidth = _boardHistory.Count.ToString().Length;

            for (int i = 0; i < _boardHistory.Count; i++)
            {
                BoardHistoryItem item = _boardHistory[i];

                string countString = (i + 1).ToString().PadLeft(countWidth) + ". ";
                string moveString  = AppVM.ViewerConfig.NotationType == NotationType.BoardSpace ? NotationUtils.NormalizeBoardSpaceMoveString(item.MoveString) : item.ToString();

                bool isActive   = i < _activeBoardHistory.Count;
                bool isLastMove = i + 1 == _activeBoardHistory.Count;

                Items.Add(new ObservableBoardHistoryItem(countString + moveString, isActive, isLastMove));
            }
        }
コード例 #2
0
        public string GetPrevMoveEran()
        {
            if (Plies <= FirstPly)
            {
                return(null);
            }

            var e = BoardHistory.Prev();

            if (e == null)
            {
                return(null);
            }

            var move = BoardHistory.Current().Move;

            if (move == null)
            {
                return(null);
            }

            return(Eran.MakeFromBoardAndMove(
                       new ChessGame(e.GCD),
                       move
                       ));
        }
コード例 #3
0
 void Update()
 {
     slider.value      = (float)i / (float)(laberintoHistory.Count - 1);
     progresoText.text = "Paso " + (i + 1) + " / " + laberintoHistory.Count;
     if (play)
     {
         //Cuando una llamada recursiva se de.
         if (nextStep && i < laberintoHistory.Count - 1)
         {
             nextStep = false;
             i       += 1;
             List <TextMeshProUGUI> auxiliar         = new List <TextMeshProUGUI>();
             List <int>             fasesAsociadas   = new List <int>();
             BoardHistory           tableroEjecucion = new BoardHistory(fasesAsociadas, auxiliar);
             //Añadimos una nueva pila de ejecución para esta llamada recursiva.
             menu.pilaEjecucion.Add(tableroEjecucion);
             if (i == 0)
             {
                 //Empezamos una nueva corutina.
                 StartCoroutine(waitForNextText(laberintoHistory[i], laberintoHistory.Count - 1 == i, laberintoBase));
             }
             else
             {
                 //Empezamos una nueva corutina.
                 StartCoroutine(waitForNextText(laberintoHistory[i], laberintoHistory.Count - 1 == i, laberintoHistory[i - 1]));
             }
         }
         else if (nextText)
         {
             nextText = false;
             //Actualizamos la fase, es decir avanzamos hacia el siguiente paso.
             fase += 1;
             if (i == 0)
             {
                 //Empezamos una nueva corutina.
                 StartCoroutine(waitForNextText(laberintoHistory[i], laberintoHistory.Count - 1 == i, laberintoBase));
             }
             else
             {
                 //Empezamos una nueva corutina.
                 StartCoroutine(waitForNextText(laberintoHistory[i], laberintoHistory.Count - 1 == i, laberintoHistory[i - 1]));
             }
         }
         else if (recuperarEstadoCorutina)
         {
             //Retomamos la corutina en la que estabamos antes de pausar la ejecucion.
             recuperarEstadoCorutina = false;
             if (i == 0)
             {
                 //Empezamos una nueva corutina.
                 StartCoroutine(waitForNextText(laberintoHistory[i], laberintoHistory.Count - 1 == i, laberintoBase));
             }
             else
             {
                 //Empezamos una nueva corutina.
                 StartCoroutine(waitForNextText(laberintoHistory[i], laberintoHistory.Count - 1 == i, laberintoHistory[i - 1]));
             }
         }
     }
 }
コード例 #4
0
        private void SetPosition(string fen)
        {
            IsSettingPosition = true;

            BoardHistory.SetInitialPosition(fen);
            MoveHistory.Clear();
            Plies = 0;
            MoveHistory.Rows.Add();
            MoveHistory.Last().No = 1;
            if (BoardHistory.Current().GCD.WhoseTurn == Player.Black)
            {
                BoardHistory.DuplicateLast();
                MoveHistory.Last().WhiteDetailedMove = null;
                Plies = 1;
                SetSelection(1);
            }
            FirstPly = Plies;

            if (int.TryParse(fen.Split(' ').Last(), out int n))
            {
                BaseMoveNumber             = n;
                MoveHistory.BaseMoveNumber = n;
                foreach (MoveHistoryDataRow row in MoveHistory.Rows)
                {
                    row.UpdateBaseMoveNumber(n);
                }
            }

            UpdateFenTextBox(fen);

            IsSettingPosition = false;
        }
コード例 #5
0
        private void DrawSquares(Graphics g, Rectangle squaresSpace)
        {
            var game  = BoardHistory.Current();
            var board = game.GetBoard();

            // We draw the square from which a piece is dragged last
            // so that it's not occluded by others.

            Position fromSquare =
                MouseFrom.HasValue
                ? ConvertPointToSquare(MouseFrom.Value)
                : null;

            for (int x = 0; x < 8; ++x)
            {
                for (int y = 0; y < 8; ++y)
                {
                    if (fromSquare != null && (int)fromSquare.File == x && fromSquare.Rank == 8 - y)
                    {
                        // this draw is deferred
                        continue;
                    }

                    Piece piece = board[y][x];
                    DrawSquare(g, piece, x, y, squaresSpace);
                }
            }
        }
コード例 #6
0
        private void MoveHistoryGridView_SelectionChanged(object sender, EventArgs e)
        {
            if (moveHistoryGridView.SelectedCells.Count == 0)
            {
                return;
            }

            var cell = moveHistoryGridView.SelectedCells[0];

            int row = cell.RowIndex;
            int col = cell.ColumnIndex;
            int ply = row * 2 + col;

            if (ply > Plies)
            {
                return;
            }

            BoardHistory.SetCurrentPly(ply);
            string fen = BoardHistory.Current().GetFen();

            if (!IsSettingPosition)
            {
                UpdateFenTextBox(fen);
            }

            chessBoardPanel.Refresh();
        }
コード例 #7
0
        private bool TryDragPiece(Point from, Point to)
        {
            Position fromSquare = ConvertPointToSquare(from);
            Position toSquare   = ConvertPointToSquare(to);

            if (fromSquare == null || toSquare == null)
            {
                return(false);
            }

            Player player = BoardHistory.Current().GCD.WhoseTurn;
            Move   move   = new Move(fromSquare, toSquare, player);

            if (BoardHistory.NeedsToBePromotion(move))
            {
                using (var dialog = new PromotionSelectionForm(PieceImages, player))
                {
                    var result = dialog.ShowDialog();
                    if (result == DialogResult.OK)
                    {
                        move.Promotion = dialog.PromotedPieceType;
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            return(DoMove(move));
        }
コード例 #8
0
 public void nextStepFunc()
 {
     if (!play && gameObject.active && !firstTime && !moverReina)
     {
         backStep  = false;
         nextStep2 = true;
         if (fase == 12 && !(boardHistory[i].diag1Ok && boardHistory[i].diag2Ok && boardHistory[i].colOk))
         {
             fase = 5;
             i   += 1;
             List <TextMeshProUGUI> auxiliar         = new List <TextMeshProUGUI>();
             List <int>             fasesAsociadas   = new List <int>();
             BoardHistory           tableroEjecucion = new BoardHistory(fasesAsociadas, auxiliar);
             //Añade una nueva pila de ejecucion
             menu.pilaEjecucion.Add(tableroEjecucion);
             faseDePintado(boardHistory[i], fase, boardHistory.Count - 1 == i);
         }
         else if (fase == 13)
         {
             fase = 0;
             i   += 1;
             List <TextMeshProUGUI> auxiliar         = new List <TextMeshProUGUI>();
             List <int>             fasesAsociadas   = new List <int>();
             BoardHistory           tableroEjecucion = new BoardHistory(fasesAsociadas, auxiliar);
             //Añade una nueva pila de ejecucion
             menu.pilaEjecucion.Add(tableroEjecucion);
             faseDePintado(boardHistory[i], fase, boardHistory.Count - 1 == i);
         }
         else if (fase == 3 && boardHistory.Count - 1 == i)
         {
             //Ejecucion terminada;
         }
         else
         {
             fase += 1;
             if (i != 0)
             {
                 faseDePintado(boardHistory[i], fase, boardHistory.Count - 1 == i);
             }
             else if (i < 0)
             {
                 i += 1;
                 List <TextMeshProUGUI> auxiliar         = new List <TextMeshProUGUI>();
                 List <int>             fasesAsociadas   = new List <int>();
                 BoardHistory           tableroEjecucion = new BoardHistory(fasesAsociadas, auxiliar);
                 faseDePintado(boardHistory[i], fase, boardHistory.Count - 1 == i);
             }
             else
             {
                 faseDePintado(boardHistory[i], fase, boardHistory.Count - 1 == i);
             }
         }
     }
 }
コード例 #9
0
        public string GetNextMoveSan()
        {
            var e = BoardHistory.Next();

            if (e == null)
            {
                return(null);
            }

            return(e.Move.SAN);
        }
コード例 #10
0
ファイル: GameEngine.cs プロジェクト: Khaleesh/Mzinga
        private void History()
        {
            if (null == _gameBoard)
            {
                throw new NoBoardException();
            }

            BoardHistory history = new BoardHistory(_gameBoard.BoardHistory);

            ConsoleOut(history.ToString());
        }
コード例 #11
0
 public void nextStepFunc()
 {
     if (!play && gameObject.active && !firstTime)
     {
         backStep = false;
         if (fase == 10 && !(laberintoHistory[i].esFactible))
         {
             fase = 6;
             i   += 1;
             List <TextMeshProUGUI> auxiliar         = new List <TextMeshProUGUI>();
             List <int>             fasesAsociadas   = new List <int>();
             BoardHistory           tableroEjecucion = new BoardHistory(fasesAsociadas, auxiliar);
             //Añade una nueva pila de ejecucion
             menu.pilaEjecucion.Add(tableroEjecucion);
             faseDePintado(laberintoHistory[i], fase, laberintoHistory.Count - 1 == i, laberintoHistory[i - 1]);
         }
         else if (fase == 11)
         {
             fase = 0;
             i   += 1;
             List <TextMeshProUGUI> auxiliar         = new List <TextMeshProUGUI>();
             List <int>             fasesAsociadas   = new List <int>();
             BoardHistory           tableroEjecucion = new BoardHistory(fasesAsociadas, auxiliar);
             //Añade una nueva pila de ejecucion
             menu.pilaEjecucion.Add(tableroEjecucion);
             faseDePintado(laberintoHistory[i], fase, laberintoHistory.Count - 1 == i, laberintoHistory[i - 1]);
         }
         else if (fase == 3 && laberintoHistory.Count - 1 == i)
         {
             //Ejecucion terminada;
         }
         else
         {
             fase += 1;
             if (i != 0)
             {
                 faseDePintado(laberintoHistory[i], fase, laberintoHistory.Count - 1 == i, laberintoHistory[i - 1]);
             }
             else if (i < 0)
             {
                 i += 1;
                 List <TextMeshProUGUI> auxiliar         = new List <TextMeshProUGUI>();
                 List <int>             fasesAsociadas   = new List <int>();
                 BoardHistory           tableroEjecucion = new BoardHistory(fasesAsociadas, auxiliar);
                 faseDePintado(laberintoHistory[i], fase, laberintoHistory.Count - 1 == i, laberintoBase);
             }
             else
             {
                 faseDePintado(laberintoHistory[i], fase, laberintoHistory.Count - 1 == i, laberintoBase);
             }
         }
     }
 }
コード例 #12
0
        /// <summary>
        /// The main method of the Console UI of the game.
        /// </summary>
        public static void Main()
        {
            var printer = new Printer();

            var reader = new Reader();

            var gameInitializator = new GameInitializer.GameInitializer(printer, reader);

            var game = gameInitializator.Initialize();

            var scoreboard = new Scoreboard();

            var commandManager = new CommandManager();

            var boardHistory = new BoardHistory();

            EngineTemplate engine = new Engine.Engine(game, scoreboard, printer, reader, commandManager, boardHistory);

            engine.Run();
        }
コード例 #13
0
        private void DrawDraggedPiece(Graphics g, Rectangle squaresSpace)
        {
            var game  = BoardHistory.Current();
            var board = game.GetBoard();

            // We draw the square from which a piece is dragged last
            // so that it's not occluded by others.

            Position fromSquare =
                MouseFrom.HasValue
                ? ConvertPointToSquare(MouseFrom.Value)
                : null;

            if (fromSquare != null)
            {
                int x = (int)fromSquare.File;
                int y = 8 - fromSquare.Rank;

                Piece piece = board[y][x];
                DrawSquare(g, piece, x, y, squaresSpace);
            }
        }
コード例 #14
0
        public bool DoMove(Move move, bool silent = false)
        {
            if (!BoardHistory.IsMoveValid(move))
            {
                return(false);
            }

            // We only synch when te move was valid
            if (!silent)
            {
                SynchronizeMoveListWithHistory();
            }

            BoardHistory.DoMove(move);
            AddMoveToMoveHistory(BoardHistory.Current().Move, silent);
            if (!silent)
            {
                moveHistoryGridView.Refresh();
                chessBoardPanel.Refresh();
            }

            return(true);
        }
コード例 #15
0
        public bool DoMove(string san, bool silent = false)
        {
            Move move = San.ParseSan(new ChessGame(BoardHistory.Current().GCD), san);

            return(DoMove(move, silent));
        }
コード例 #16
0
        public static IEnumerable <Tuple <ViewerBoard, BoardHistoryItem> > EnumerateWithBoard(this BoardHistory boardHistory, ViewerBoard currentBoard)
        {
            // Create a copy of the current board
            ViewerBoard board = new ViewerBoard(currentBoard.ToString());

            List <BoardHistoryItem> reversedHistory = new List <BoardHistoryItem>(boardHistory);

            reversedHistory.Reverse();

            // "Undo" moves in the boardHistory
            foreach (BoardHistoryItem item in reversedHistory)
            {
                board.SimulateUndo(item);
            }

            // "Play" forward returning the board state along the way
            foreach (BoardHistoryItem item in boardHistory)
            {
                yield return(new Tuple <ViewerBoard, BoardHistoryItem>(board, item));

                board.SimulatePlay(item.Move);
            }
        }
コード例 #17
0
 public string GetLastMoveSan()
 {
     return(BoardHistory.Current().GetSan());
 }
コード例 #18
0
 public string GetPrevFen()
 {
     return(BoardHistory.Prev().GetFen());
 }
コード例 #19
0
 void Update()
 {
     slider.value      = (float)i / (float)(boardHistory.Count - 1);
     progresoText.text = "Paso " + (i + 1) + " / " + boardHistory.Count;
     //Si una reina se esta moviendo, la ejecucion se espera a que finalize.
     if (moverReina)
     {
         moverReinas();
     }
     else if (play)
     {
         //Cuando una llamada recursiva se de.
         if (nextStep && i < boardHistory.Count - 1)
         {
             nextStep = false;
             i       += 1;
             List <TextMeshProUGUI> auxiliar         = new List <TextMeshProUGUI>();
             List <int>             fasesAsociadas   = new List <int>();
             BoardHistory           tableroEjecucion = new BoardHistory(fasesAsociadas, auxiliar);
             //Añadimos una nueva pila de ejecución para esta llamada recursiva.
             menu.pilaEjecucion.Add(tableroEjecucion);
             //Empezamos una corutina.
             StartCoroutine(waitForNextText(boardHistory[i], boardHistory.Count - 1 == i));
         }
         else if (nextText)
         {
             nextText = false;
             //Actualizamos la fase, es decir avanzamos hacia el siguiente paso.
             fase += 1;
             //Empezamos una corutina.
             StartCoroutine(waitForNextText(boardHistory[i], boardHistory.Count - 1 == i));
         }
         else if (recuperarEstadoCorutina)
         {
             recuperarEstadoCorutina = false;
             //Retomamos la corutina en la que estabamos antes de pausar la ejecucion.
             StartCoroutine(waitForNextText(boardHistory[i], boardHistory.Count - 1 == i));
         }
     }
     //Mostramos el numero de llamadas recursivas hechas asi como la fila y la columna actual del tablero.
     if ((play || backStep || nextStep2) && !(boardHistory.Count - 1 == i))
     {
         foreach (GameObject funcion in llamadasRecursivas)
         {
             funcion.gameObject.SetActive(false);
         }
         filActualText.text = "Fil actual: " + boardHistory[i].vectorSolucion.Count;
         foreach (int ultimo in boardHistory[i].vectorSolucion)
         {
             colActual = ultimo + 1;
         }
         colActualText.text = "Col actual: " + colActual;
         for (int j = 0; j < boardHistory[i].vectorSolucion.Count - 1; j++)
         {
             llamadasRecursivas[j].gameObject.SetActive(true);
         }
         for (int j = 0; j <= boardHistory[i].vectorSolucion.Count - 1; j++)
         {
             pieLlamada[j].text = "" + (boardHistory[i].vectorSolucion.Count - j);
         }
     }
 }
コード例 #20
0
 public string GetFen()
 {
     return(BoardHistory.Current().GetFen());
 }
コード例 #21
0
 internal Player SideToMove()
 {
     return(BoardHistory.Current().GCD.WhoseTurn);
 }