Beispiel #1
0
        private AIResponse HandleRegularMove(IChessboard chessboard)
        {
            var boxesWithPieces = ChessboardBoxesHelper.GetBoxesThatHavePieces(chessboard, Turn);

            if (boxesWithPieces.Count == 0)
            {
                return(AIResponse.NoPiecesLeft);
            }

            var allAvailableMoves = new List <Tuple <Box, Box> >();

            foreach (var boxWithPiece in boxesWithPieces)
            {
                var availableMoves = GetAvailableMovesFromBox(chessboard, boxWithPiece);
                allAvailableMoves.AddRange(availableMoves);
            }

            if (allAvailableMoves.Count == 0)
            {
                return(AIResponse.NoMovesLeft);
            }

            var move = ChooseMove(allAvailableMoves);

            chessboard.Move(move.Item1.Position, move.Item2.Position);

            return(AIResponse.SuccessfulMove);
        }
Beispiel #2
0
        private void MovePiece(Box origin, Box destination)
        {
            // TODO: Check if move is valid

            if (chessboard.CurrentTurn == playerTurn)
            {
                networkManager?.NotifyOfMove(origin.Position, destination.Position);
            }

            SetChessboardBoxesColors(ignoreIsAvailableFlag: true);
            TriggerOnMadeMove(origin, destination);
            chessboard.Move(origin.Position, destination.Position);

            if (SoundEnabled)
            {
                soundManager.PlayMoveSound();
            }

            if (!chessboard.RetakingIsActive)
            {
                EndTurn();
            }
        }