Exemplo n.º 1
0
        public double Eval(CheckersBoard board, int level, PieceColor playerColor)
        {
            {
                double eval = 0;

                for (int x = 0; x < board.Width; x++)
                    for (int y = 0; y < board.Height; y++)
                    {
                        var piece = board.GetPieceAt(x, y) as CheckersPiece;
                        if (piece != null)
                        {
                            if (piece.Color == playerColor)
                            {
                                if (piece is Pawn) eval += _ownPawnStrength;
                                else if (piece is Queen) eval += _ownQueenStrength;
                            }
                            else
                            {
                                if (piece is Pawn) eval -= _ownPawnStrength;
                                else if (piece is Queen) eval -= _ownQueenStrength;
                            }
                        }
                    }

                return eval;
            }
        }
        public double Eval(CheckersBoard board, int level, PieceColor playerColor)
        {
            {
                double myval = 0;
                double enemyval = 0;
                for (int x = 0; x < board.Width; x++)
                    for (int y = 0; y < board.Height; y++)
                    {
                        CheckersPiece piece = board.GetPieceAt(x, y) as CheckersPiece;
                        if (piece != null)
                        {
                            int factor = (piece.Color == PieceColor.White) ? (7 - y) : (y);
                            if (piece.Color == playerColor)
                            {
                                if (piece is Pawn) myval += 100 + (factor * factor);
                                else
                                {

                                    myval += 200;
                                    if (y == 0)
                                    {
                                        if (x == 0) myval -= 40;
                                        else myval -= 20;
                                    }
                                    else if (y == 7)
                                    {
                                        if (x == 7) myval -= 40;
                                        else myval -= 20;
                                    }
                                }
                            }
                            else
                            {
                                if (piece is Pawn) enemyval += 100 + (factor * factor);
                                else
                                {
                                    enemyval += 200;
                                    if (y == 0)
                                    {
                                        if (x == 0) enemyval -= 40;
                                        else enemyval -= 20;
                                    }
                                    else if (y == 7)
                                    {
                                        if (x == 7) enemyval -= 40;
                                        else enemyval -= 20;
                                    }
                                }
                            }
                        }
                    }

                if (enemyval == 0) return 100000 + level * level;
                else if (myval == 0) return -100000 - level * level;
                return (myval - enemyval);
            }
        }
Exemplo n.º 3
0
        public void Test9()
        {
            CheckersBoard board = new CheckersBoard(10, new List <Piece>()
            {
                new Piece(3, 5, PieceColor.White, 10, true),
                new Piece(4, 6, PieceColor.Black, 10, true),
                new Piece(6, 8, PieceColor.Black, 10, true),
                new Piece(7, 5, PieceColor.Black, 10, true),
                new Piece(7, 3, PieceColor.Black, 10, true),
                new Piece(3, 1, PieceColor.Black, 10, true)
            });
            var moves = board.GetAllPossibleMoves(PieceColor.White);

            Assert.IsTrue(moves.Where(m => m.BeatedPieces?.Count == 4).Count() > 0);
        }
Exemplo n.º 4
0
 public AlphaBetaNode(CheckersBoard board, Move move, PieceColor color, int depthLevel)
 {
     Board      = board;
     Color      = color;
     DepthLevel = depthLevel;
     Move       = move;
     if (Color == PieceColor.White)
     {
         CurrentScore = int.MinValue;
     }
     else
     {
         CurrentScore = int.MaxValue;
     }
 }
Exemplo n.º 5
0
        public double Eval(CheckersBoard board, int level, PieceColor playerColor)
        {
            double eval = 0.0;

            for (int x = 0; x < board.Width; x++)
                for (int y = 0; y < board.Height; y++)
                {
                    var piece = board.GetPieceAt(x, y) as CheckersPiece;
                    if (piece != null)
                    {
                        eval += GetPiecePoints(board,piece, playerColor);
                    }
                }

            return eval;
        }
Exemplo n.º 6
0
        public void Test5()
        {
            CheckersBoard board = new CheckersBoard(10, new List <Piece>()
            {
                new Piece(1, 1, PieceColor.White, 10, true),
                new Piece(3, 3, PieceColor.Black, 10, false),
                new Piece(2, 4, PieceColor.Black, 10, false),
                new Piece(2, 6, PieceColor.Black, 10, false),
                new Piece(2, 8, PieceColor.Black, 10, false),
                new Piece(4, 8, PieceColor.Black, 10, false),
                new Piece(8, 2, PieceColor.Black, 10, false),
                new Piece(8, 4, PieceColor.Black, 10, false),
                new Piece(6, 6, PieceColor.Black, 10, false)
            });
            var moves = board.GetAllPossibleMoves(PieceColor.White);

            Assert.IsTrue(moves.Where(m => m.BeatedPieces?.Count == 7).Count() > 0 && moves.Where(m => m.BeatedPieces.Last().Row == 4 || m.BeatedPieces.Last().Column == 8).Count() == 0);
        }
Exemplo n.º 7
0
        private double GetPiecePoints(CheckersBoard board,CheckersPiece piece, PieceColor playerColor)
        {
            int area = 1;
            if (piece.X <= Area2Width || piece.X >= board.Width - Area2Width || piece.Y <= Area2Width ||
                piece.Y >= board.Height - Area2Width) area = 2;

            double points = 0;
            if (piece is Pawn)
            {
                points = area == 2 ? _pawnStrengthArea2 : _pawnStrengthArea1;
            }
            else if (piece is Queen)
            {
                points = area == 2 ? _queenStrengthArea2 : _queenStrengthArea1;
            }

            return points * (piece.Color == playerColor ? 1 : -1);
        }
 private void Start()
 {
     Instance = this;
     client   = FindObjectOfType <Client>();
     if (client)
     {
         //isWhite = client.isHost;
         Alert(client.players[0].name + " versus " + client.players[1].name);
     }
     else
     {
         Alert("White player's turn");
     }
     isWhiteTurn  = true;
     forcedPieces = new List <Piece>();
     GenerateBoard();
     CheckVictory();
 }
Exemplo n.º 9
0
        public void CountPieceChancesToBeCaptured_CanAndCannotCapture_CapturedCount()
        {
            var target = new CheckersBoard(8);
            var piece  = target.GetSquare(1, 2).CurrentPiece;

            Assert.IsTrue(target.MovePiece(new CheckersMove(piece, target.GetSquare(2, 3))));
            Assert.AreEqual(0, target.CountPieceChancesToBeCaptured(piece));

            Assert.IsTrue(target.MovePiece(new CheckersMove(piece, target.GetSquare(3, 4))));
            Assert.AreEqual(2, target.CountPieceChancesToBeCaptured(piece));

            var enemyPiece = target.GetSquare(4, 5).CurrentPiece;

            Assert.AreEqual(0, target.CountPieceChancesToBeCaptured(enemyPiece));

            Assert.IsFalse(target.MovePiece(new CheckersMove(piece, target.GetSquare(4, 5))));
            Assert.AreEqual(2, target.CountPieceChancesToBeCaptured(piece));
        }
Exemplo n.º 10
0
    private void Start()
    {
        _ns = FindObjectOfType <NextScene>();

        _checkers = new CheckersBoard {
            Client = FindObjectOfType <Client>()
        };


        if (_ns.mode == GameMode.MultiPlayer)
        {
            Alert(_checkers.Client.players[0].Name + " versus " + _checkers.Client.players[1].Name);
        }
        else
        {
            Alert("White player's turn");
        }

        _checkers.MovePieces += (p, x, y) => MovePiece(pieces[p], x, y);
        _checkers.OnDestr    += (p) => DestroyImmediate(pieces[p].gameObject);
        _checkers.OnKing     += (p) => pieces[p].transform.Rotate(Vector3.right * 180);
        //checkers.client.OnTryMove += (x1, y1, x2, y2) => TryMove(x1, y1, x2, y2);
        _checkers.OnEndTurn += (isWhiteTurn, client) =>
        {
            string str;
            if (client)
            {
                str = isWhiteTurn ? _checkers.Client.players[0].Name : _checkers.Client.players[1].Name;
            }
            else
            {
                str = isWhiteTurn ? "White" : "Black";
            }

            Alert(str + " players turn");
        };

        if (_checkers.Client != null)
        {
            _checkers.Client.OnTryMove += TryMove;
        }

        GenerateBoard();
    }
Exemplo n.º 11
0
        public void Test8()
        {
            CheckersBoard board = new CheckersBoard(10, new List <Piece>()
            {
                new Piece(2, 2, PieceColor.White, 10, false),
                new Piece(3, 3, PieceColor.Black, 10, false),
                new Piece(2, 4, PieceColor.Black, 10, false),
                new Piece(3, 5, PieceColor.Black, 10, false),
                new Piece(2, 8, PieceColor.Black, 10, false),
                new Piece(1, 5, PieceColor.Black, 10, false),
                new Piece(3, 7, PieceColor.Black, 10, false),
                new Piece(7, 3, PieceColor.Black, 10, false),
                new Piece(7, 5, PieceColor.Black, 10, false),
                new Piece(5, 7, PieceColor.Black, 10, false)
            });
            var moves = board.GetAllPossibleMoves(PieceColor.White);

            Assert.IsTrue(moves.Where(m => m.BeatedPieces?.Count == 6).Count() > 0);
        }
Exemplo n.º 12
0
        public void SetBoard(CheckersBoard i_DataBoard)
        {
            char rowKey    = i_DataBoard.MinRowKey;
            char columnKey = i_DataBoard.MinColumnKey;

            m_Board.Clear();
            m_Board.Append(m_ColumnKeysRow);
            m_Board.Append(m_SpaceRow);

            foreach (KeyValuePair <string, BoardSlot> slot in i_DataBoard.Dictionary)
            {
            }
            for (int i = 0; i < i_DataBoard.Size; i++)
            {
                addRow(ref m_Board, i_DataBoard, rowKey);
                m_Board.Append(m_SpaceRow);
                rowKey++;
            }
        }
Exemplo n.º 13
0
    private void Start()
    {
        Instance    = this;
        _gameIsOver = false;
        _client     = FindObjectOfType <Client>();

        foreach (Transform t in highlightContainer.transform)
        {
            t.position = Vector3.down * 5;
        }

        Alert(_client.players[0].name + " VS " + _client.players[1].name);

        isWhite = _client.isHost;

        _isWhiteTurn  = true;
        _forcedPieces = new List <Piece>();
        GenerateBoard();
    }
Exemplo n.º 14
0
        public Move MakeMove(CheckersBoard currentBoard, GameVariant variant, List <Move> gameMoves)
        {
            List <Move> allPossibleMoves = currentBoard.GetAllPossibleMoves(Color);
            int         count            = allPossibleMoves.Count;

            if (count == 0)
            {
                throw new NotAvailableMoveException(Color);
            }
            if (count == 1)
            {
                return(allPossibleMoves.First());
            }
            else
            {
                MctsTree tree      = new MctsTree(NumberOfIterations, UctParameter, randomGenerator, currentBoard, Color);
                int      elemIndex = tree.ChooseBestMove(variant, gameMoves);
                return(allPossibleMoves[elemIndex]);
            }
        }
Exemplo n.º 15
0
        public Move MakeMove(CheckersBoard currentBoard, GameVariant variant, List <Move> gameMoves)
        {
            List <Move> allPossibleMoves = currentBoard.GetAllPossibleMoves(Color);
            int         count            = allPossibleMoves.Count;

            if (count == 0)
            {
                throw new NotAvailableMoveException(Color);
            }
            if (count == 1)
            {
                return(allPossibleMoves.First());
            }
            else
            {
                AlphaBetaTree tree      = new AlphaBetaTree(AlphaBetaTreeDepth, Color, currentBoard);
                int           elemIndex = tree.ChooseBestMove(variant, gameMoves);
                return(allPossibleMoves[elemIndex]);
            }
        }
Exemplo n.º 16
0
    /// <sumary>
    ///   Evaluates the strength of the current player
    /// </sumary>
    /// <param name="board">
    ///   The board where the current player position will be evaluated.
    /// </param>
    /// <value>
    ///  Player strength
    /// </value>
    private int eval(CheckersBoard board)
    {
        int colorKing;
        int colorForce = 0;
        int enemyForce = 0;
        int piece;

        if (color == CheckersBoard.WHITE)
        {
            colorKing = CheckersBoard.WHITE_KING;
        }
        else
        {
            colorKing = CheckersBoard.BLACK_KING;
        }

        try {
            for (int i = 0; i < 32; i++)
            {
                piece = board.getPiece(i);

                if (piece != CheckersBoard.EMPTY)
                {
                    if (piece == color || piece == colorKing)
                    {
                        colorForce += calculateValue(piece, i);
                    }
                    else
                    {
                        enemyForce += calculateValue(piece, i);
                    }
                }
            }
        }
        catch (BadCoord bad) {
            Debug.WriteLine(bad.StackTrace);
            Application.Exit();
        }

        return(colorForce - enemyForce);
    }
Exemplo n.º 17
0
    /// <sumary>
    ///   Implements game move evaluation from the point of view of the
    ///  MIN player.
    /// </sumary>
    /// <param name="board">
    ///   The board that will be used as a starting point
    ///  for generating the game movements
    /// </param>
    /// <param name="depth">
    ///   Current depth in the Min-Max tree
    /// </param>
    /// <param name="alpha">
    ///   Current alpha value for the alpha-beta cutoff
    /// </param>
    /// <param name="beta">
    ///   Current beta value for the alpha-beta cutoff
    /// </param>
    /// <value>
    ///  Move evaluation value
    /// </value>
    private int minMove(CheckersBoard board, int depth, int alpha, int beta)
    {
        if (cutOffTest(board, depth))
        {
            return(eval(board));
        }


        List          sucessors;
        List          move;
        CheckersBoard nextBoard;
        int           value;

        Debug.WriteLine("Min node at depth : " + depth + " with alpha : " + alpha +
                        " beta : " + beta);

        sucessors = (List)board.legalMoves();
        while (mayPlay(sucessors))
        {
            move      = (List)sucessors.pop_front();
            nextBoard = (CheckersBoard)board.clone();
            nextBoard.move(move);
            value = maxMove(nextBoard, depth + 1, alpha, beta);

            if (value < beta)
            {
                beta = value;
                Debug.WriteLine("Min value : " + value + " at depth : " + depth);
            }

            if (beta < alpha)
            {
                Debug.WriteLine("Min value with prunning : " + alpha + " at depth : " + depth);
                Debug.WriteLine(sucessors.length() + " sucessors left");
                return(alpha);
            }
        }

        Debug.WriteLine("Min value selected : " + beta + " at depth : " + depth);
        return(beta);
    }
Exemplo n.º 18
0
    private void Start()
    {
        Instance = this;
        client   = FindObjectOfType <Client>();

        if (client)
        {
            alertCanvas1.SetActive(false);
            isWhite = client.isHost;
            Alert(client.players[0].name + " vs " + client.players[1].name);
        }
        else
        {
            Alert("White player's turn");
        }

        //     isWhite = true;
        isWhiteTurn  = true;
        forcedPieces = new List <Piece>();
        GenerateBoard();
    }
Exemplo n.º 19
0
    private void Start()
    {
        GenerateBoard();
        forcedPieces   = new List <Piece>();
        moveIndicators = new List <GameObject>();
        isWhiteTurn    = true;
        isWhite        = true;
        gameManager    = GameManager.Instance;
        Instance       = GetComponent <CheckersBoard>();

        if (gameManager)
        {
            isWhite  = gameManager.isWhite;
            isOnline = gameManager.isOnline;
        }

        if (isOnline && !isWhite)
        {
            FlipTable();
        }
    }
Exemplo n.º 20
0
    /// <sumary>
    ///  Loads a saved game from a file stream
    /// </sumary>
    /// <param name="file">
    ///  The source stream
    /// </param>
    public void loadBoard(Stream file)
    {
        try {
            IFormatter formatter = (IFormatter) new BinaryFormatter();

            // Clear the selected moves, just in case
            selected.clear();
            Invalidate();
            reset();

            // Deserializes the object graph to stream
            board = (CheckersBoard)formatter.Deserialize(file);

            // Create a new computer instace for this board
            computer = new Computer(board);
        }
        catch {
            MessageBox.Show("Error while loading", "Error",
                            MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }
Exemplo n.º 21
0
        public Move MakeMove(CheckersBoard currentBoard, GameVariant variant, List <Move> gameMoves)
        {
            List <Move> allPossibleMoves = currentBoard.GetAllPossibleMoves(Color);
            int         count            = allPossibleMoves.Count;

            if (count == 0)
            {
                throw new NotAvailableMoveException(Color);
            }
            StringBuilder stringBuilder = new StringBuilder();

            foreach (var move in allPossibleMoves)
            {
                stringBuilder.Append($"{GetPossibility(move)}, ");
            }
            stringBuilder.Remove(stringBuilder.Length - 2, 2);
            int beatedPawns = allPossibleMoves[0].BeatedPieces?.Count ?? 1;

            if (HumanMove.Count == 1 + beatedPawns)
            {
                var possibleMoves = allPossibleMoves.Where(m => m.OldPiece.Position == HumanMove[0].Position && m.NewPiece.Position == HumanMove.Last().Position).ToList();
                HumanMove.Remove(HumanMove.First());
                HumanMove.Remove(HumanMove.Last());
                for (int i = 0; i < HumanMove.Count; i++)
                {
                    possibleMoves = possibleMoves.Where(p => p.BeatedPieces[i + 1].BeatPieceColumn == HumanMove[i].Column && p.BeatedPieces[i + 1].BeatPieceRow == HumanMove[i].Row).ToList();
                }
                var humanMove = possibleMoves.SingleOrDefault();
                if (humanMove == null)
                {
                    throw new WrongMoveException(allPossibleMoves[0].BeatedPieces == null ? 0 : beatedPawns, stringBuilder.ToString());
                }
                return(humanMove);
            }
            else
            {
                throw new WrongMoveException(allPossibleMoves[0].BeatedPieces == null ? 0 : beatedPawns, stringBuilder.ToString());
            }
        }
Exemplo n.º 22
0
        public void Contructor_ValidSize_PlayerTwoPiecedPlaced()
        {
            var target = new CheckersBoard(8);

            Assert.AreEqual(8, target.Size);

            // first row.
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerTwo, target.GetSquare(0, 7).State);
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerTwo, target.GetSquare(2, 7).State);
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerTwo, target.GetSquare(4, 7).State);
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerTwo, target.GetSquare(6, 7).State);

            // second row
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerTwo, target.GetSquare(1, 6).State);
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerTwo, target.GetSquare(3, 6).State);
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerTwo, target.GetSquare(5, 6).State);
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerTwo, target.GetSquare(7, 6).State);

            // third row
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerTwo, target.GetSquare(0, 5).State);
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerTwo, target.GetSquare(2, 5).State);
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerTwo, target.GetSquare(4, 5).State);
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerTwo, target.GetSquare(6, 5).State);
        }
Exemplo n.º 23
0
        public void Contructor_ValidSize_FreeAndNotPlayableSquaresOk()
        {
            var target = new CheckersBoard(8);

            Assert.AreEqual(8, target.Size);

            for (int c = 0; c < 8; c++)
            {
                for (int r = 0; r < 8; r++)
                {
                    var notPlayable = CheckersSquare.IsNotPlayableSquare(c, r);
                    var actual      = target.GetSquare(c, r).State;

                    if (notPlayable)
                    {
                        Assert.AreEqual(CheckersSquareState.NotPlayable, actual);
                    }
                    else
                    {
                        Assert.AreNotEqual(CheckersSquareState.NotPlayable, actual);
                    }
                }
            }
        }
Exemplo n.º 24
0
        public void Contructor_ValidSize_PlayerOnePiecedPlaced()
        {
            var target = new CheckersBoard(8);

            Assert.AreEqual(8, target.Size);

            // First row.
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerOne, target.GetSquare(1, 0).State);
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerOne, target.GetSquare(3, 0).State);
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerOne, target.GetSquare(5, 0).State);
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerOne, target.GetSquare(7, 0).State);

            // second row
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerOne, target.GetSquare(0, 1).State);
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerOne, target.GetSquare(2, 1).State);
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerOne, target.GetSquare(4, 1).State);
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerOne, target.GetSquare(6, 1).State);

            // third row
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerOne, target.GetSquare(1, 2).State);
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerOne, target.GetSquare(3, 2).State);
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerOne, target.GetSquare(5, 2).State);
            Assert.AreEqual(CheckersSquareState.OccupiedByPlayerOne, target.GetSquare(7, 2).State);
        }
Exemplo n.º 25
0
        public void GetSize_InvalidIndexes_Exception()
        {
            var target = new CheckersBoard(10);

            ExceptionAssert.IsThrowing(new ArgumentOutOfRangeException("columnIndex"), () =>
            {
                target.GetSquare(-1, 0);
            });

            ExceptionAssert.IsThrowing(new ArgumentOutOfRangeException("columnIndex"), () =>
            {
                target.GetSquare(10, 0);
            });

            ExceptionAssert.IsThrowing(new ArgumentOutOfRangeException("rowIndex"), () =>
            {
                target.GetSquare(0, -1);
            });

            ExceptionAssert.IsThrowing(new ArgumentOutOfRangeException("rowIndex"), () =>
            {
                target.GetSquare(0, 10);
            });
        }
Exemplo n.º 26
0
        public void MovePiece_ValidMove_True()
        {
            var target = new CheckersBoard(8);

            // Move to occupied square to right side.
            var move = new CheckersMove(new CheckersPiece(CheckersPlayer.PlayerOne)
            {
                CurrentSquare = new CheckersSquare(3, 2)
            }, new CheckersSquare(4, 3));

            Assert.IsTrue(target.MovePiece(move));

            move = new CheckersMove(new CheckersPiece(CheckersPlayer.PlayerTwo)
            {
                CurrentSquare = new CheckersSquare(6, 5)
            }, new CheckersSquare(5, 4));
            Assert.IsTrue(target.MovePiece(move));

            move = new CheckersMove(new CheckersPiece(CheckersPlayer.PlayerOne)
            {
                CurrentSquare = new CheckersSquare(4, 3)
            }, new CheckersSquare(6, 5));
            Assert.IsTrue(target.MovePiece(move));
        }
    //private Client client;

    //public FingerModel fingerRight;
    //public FingerModel fingerLeft;

    /* [SerializeField]
     * private PinchDetector _pinchDetectorA;
     * public PinchDetector PinchDetectorA
     * {
     *   get
     *   {
     *       return _pinchDetectorA;
     *   }
     *   set
     *   {
     *       _pinchDetectorA = value;
     *   }
     * }
     *
     * [SerializeField]
     * private PinchDetector _pinchDetectorB;
     * public PinchDetector PinchDetectorB
     * {
     *   get
     *   {
     *       return _pinchDetectorB;
     *   }
     *   set
     *   {
     *       _pinchDetectorB = value;
     *   }
     * }
     */

    private void Start()
    {
        Instance = this;
        // client = FindObjectOfType<Client>();

        foreach (Transform t in highlightsContainer.transform)
        {
            t.position = Vector3.down * 100;
        }

        /* if (client)
         * {
         *   isWhite = client.isHost;
         *   Alert(client.players[0].name + " VS " + client.players[1].name);
         * }
         * else
         * {
         *   Alert("WHITE PLAYER STARTS");
         * }
         */
        isWhiteTurn  = true;
        forcedPieces = new List <Piece>();
        GenerateBoard();
    }
Exemplo n.º 28
0
 public MctsTree(int numberOfIterations, double uctParameter, Random generator, CheckersBoard board, PieceColor color)
 {
     NumberOfTotalSimulations = 0;
     NumberOfIterations       = numberOfIterations;
     UctParameter             = uctParameter;
     RandomGenerator          = generator;
     Root = new MctsNode(color, board, null);
 }
Exemplo n.º 29
0
 public AlphaBetaTree(int depth, PieceColor color, CheckersBoard board)
 {
     Depth = depth;
     Root  = new AlphaBetaNode(board, null, color, 0);
 }
Exemplo n.º 30
0
        public void MovePiece_InvalidMove_False()
        {
            var target = new CheckersBoard(8);

            // Horizontal move.
            var move = new CheckersMove(new CheckersPiece(CheckersPlayer.PlayerOne)
            {
                CurrentSquare = new CheckersSquare(1, 0)
            }, new CheckersSquare(3, 0));

            Assert.IsFalse(target.MovePiece(move));

            // Vertical move.
            move = new CheckersMove(new CheckersPiece(CheckersPlayer.PlayerOne)
            {
                CurrentSquare = new CheckersSquare(1, 0)
            }, new CheckersSquare(1, 2));
            Assert.IsFalse(target.MovePiece(move));

            // Back move.
            move = new CheckersMove(new CheckersPiece(CheckersPlayer.PlayerOne)
            {
                CurrentSquare = new CheckersSquare(2, 3)
            }, new CheckersSquare(1, 2));
            Assert.IsFalse(target.MovePiece(move));

            // Move to occupied square to right side.
            move = new CheckersMove(new CheckersPiece(CheckersPlayer.PlayerOne)
            {
                CurrentSquare = new CheckersSquare(1, 2)
            }, new CheckersSquare(2, 3));
            Assert.IsTrue(target.MovePiece(move));
            move = new CheckersMove(new CheckersPiece(CheckersPlayer.PlayerOne)
            {
                CurrentSquare = new CheckersSquare(2, 3)
            }, new CheckersSquare(3, 4));
            Assert.IsTrue(target.MovePiece(move));
            move = new CheckersMove(new CheckersPiece(CheckersPlayer.PlayerOne)
            {
                CurrentSquare = new CheckersSquare(3, 4)
            }, new CheckersSquare(4, 5));                                                                                                               // Occupied.
            Assert.IsFalse(target.MovePiece(move));

            // Move to occupied square to left side.
            move = new CheckersMove(new CheckersPiece(CheckersPlayer.PlayerOne)
            {
                CurrentSquare = new CheckersSquare(7, 2)
            }, new CheckersSquare(6, 3));
            Assert.IsTrue(target.MovePiece(move));
            move = new CheckersMove(new CheckersPiece(CheckersPlayer.PlayerOne)
            {
                CurrentSquare = new CheckersSquare(6, 3)
            }, new CheckersSquare(5, 4));
            Assert.IsTrue(target.MovePiece(move));
            move = new CheckersMove(new CheckersPiece(CheckersPlayer.PlayerOne)
            {
                CurrentSquare = new CheckersSquare(5, 4)
            }, new CheckersSquare(6, 5));                                                                                                                           // Occupied.
            Assert.IsFalse(target.MovePiece(move));

            // Move more than 1 square not capturing.
            move = new CheckersMove(new CheckersPiece(CheckersPlayer.PlayerOne)
            {
                CurrentSquare = new CheckersSquare(1, 2)
            }, new CheckersSquare(3, 4));
            Assert.IsFalse(target.MovePiece(move));
        }
Exemplo n.º 31
0
 /**
  * Constructor.
  * @param gameBoard Tabuleiro que o computador deve usar para efectuar as jogadas.
  */
 public Computer(CheckersBoard gameBoard)
 {
     currentBoard = gameBoard;
     color        = CheckersBoard.BLACK;
 }
Exemplo n.º 32
0
 /// <sumary>
 ///   Changes the checkers board that is hold by the computer.
 /// </sumary>
 /// <param name="board">
 ///  The new checkers board
 /// </param>
 public void setBoard(CheckersBoard board)
 {
     currentBoard = board;
 }
Exemplo n.º 33
0
 /// <sumary>
 ///   Verifies if the game tree can be prunned
 /// </sumary>
 /// <param name="board">
 ///   The board to evaluate
 /// </param>
 /// <param name="depth">
 ///   Current game tree depth
 /// </param>
 /// <value>
 ///  true if the tree can be prunned.
 /// </value>
 private bool cutOffTest(CheckersBoard board, int depth)
 {
     return(depth > maxDepth || board.hasEnded());
 }