Пример #1
0
        public override void DoTurn()
        {
            var cells = GameBoard.Instance.GetCells();

            cells.RemoveAll(c => c.piece == null);
            cells.RemoveAll(c => c.piece.color != color);

            while (cells.Count > 0)
            {
                var cell = cells.RandomItem();
                cells.Remove(cell);

                List <Move> moves = MoveGenerator.GenerateMoves(cell);
                while (moves.Count > 0)
                {
                    var move = moves.RandomItem();
                    moves.Remove(move);

                    turn = new Turn(cell, GameBoard.Instance.GetCell(move.targetPosition))
                    {
                        extraCaptures = move.extraCaptures
                    };

                    OnTurnCompleted?.Invoke(turn);
                    return;
                }
            }

            // There are no possible moves for any of the pieces
        }
Пример #2
0
        private void AttemptMove(Cell cell)
        {
            // Generate a set of all valid moves for the starting piece
            var moves     = MoveGenerator.GenerateMoves(turn.start);
            var validMove = moves.Where(m => m.targetPosition == cell.position).FirstOrDefault();

            // If the move we want to take is one of the valid moves, we can continue
            if (validMove != null)
            {
                // Moving to an empty space is fine. Capturing is only allowed if the piece is of opposite color to you.
                if (cell.piece == null || (cell.piece != null && cell.piece.color != color))
                {
                    turn.end = cell;
                    OnTurnCompleted?.Invoke(turn);
                    turnManager.selectedCell = null;
                }
            }
        }