Exemple #1
0
        public void evaluateBoarRows(int expected, string board)
        {
            Board b      = new Board(board, true);
            int   actual = BoardEvaluator.evaluateBoard(b);

            Assert.Equal(expected, actual);
        }
Exemple #2
0
 public void CreateGameBoard(int boardSize)
 {
     this.boardSize = boardSize;
     DestroyGameBoard();
     CreateBoardTiles();
     StartCoroutine(ShowBoardTiles());
     evaluator = new BoardEvaluator(boardSize);
 }
Exemple #3
0
        static int AlphaBeta(int depth, int alpha, int beta, PieceColor color)
        {
            if (depth == 0)
            {
                return(BoardEvaluator.GetBoardScore(color));
            }

            int        value      = -99999;
            bool       pv         = false;
            PieceColor enemyColor = color == PieceColor.WHITE ? PieceColor.BLACK : PieceColor.WHITE;

            if (depth >= 3)
            {
                value = -AlphaBeta(depth - (depth > 6 ? 3 : 2) - 1, -beta, -beta + 1, enemyColor);
                if (value >= beta)
                {
                    return(beta);
                }
            }

            System.Collections.ArrayList moves = Board.GenerateValidMoves(color, true);
            moves.Sort(new SortByScore());
            foreach (Move move in moves)
            {
                char[,] backBoard = new char[8, 8];
                Array.Copy(Board.pieces, backBoard, Board.pieces.Length);
                int c = move.From / 8, r = move.From % 8, c2 = move.To / 8, r2 = move.To % 8;
                Board.pieces[c2, r2] = Board.pieces[c, r];
                Board.pieces[c, r]   = '\0';
                if (pv)
                {
                    value = -AlphaBeta(depth - 1, -alpha - 1, -alpha, enemyColor);
                    if (value > alpha && value < beta)
                    {
                        value = -AlphaBeta(depth - 1, -beta, -alpha, enemyColor);
                    }
                }
                else
                {
                    value = -AlphaBeta(depth - 1, -beta, -alpha, enemyColor);
                }
                Array.Copy(backBoard, Board.pieces, backBoard.Length);

                if (value >= beta)
                {
                    return(beta);
                }

                if (value > alpha)
                {
                    alpha = value;
                    pv    = true;
                }
            }

            return(alpha);
        }
Exemple #4
0
    private void Awake()
    {
        instance = this;

        /* We are using the method of pre calculating every board
         * position and storing it in a hashtable to evaluate a winner*/
        FieldResultLookUp = new Dictionary <Field[], WinState>(new FieldComparer());
        CalculateResultForEveryPossibleField();
    }
        public void EvaluateWeakPosition()
        {
            var board = EngineTests.GenerateGameWithPlayerAboutToLose();

            var evaluation = BoardEvaluator.Evaluate(board);

            this.TestContext.WriteLine("Evaluation = " +
                                       evaluation.ToString(CultureInfo.CurrentCulture));
            Assert.IsTrue(evaluation < 0);             // -116
        }
        public void EvaluateComplexGame()
        {
            var board = EngineTests.GenerateComplexGame();

            var evaluation = BoardEvaluator.Evaluate(board);

            this.TestContext.WriteLine("Evaluation = " +
                                       evaluation.ToString(CultureInfo.CurrentCulture));
            Assert.IsTrue(evaluation < 0);             // -3
        }
        public void HasWinningColumn_ForColumns_WithWinCondition()
        {
            for (var x = 0; x < GridSize; x++)
            {
                var board = new Board(GridSize);
                FillColumn(board, x);

                Assert.True(BoardEvaluator.HasWinningColumn(board));
            }
        }
        public void HasWinningRow_ForRows_WithWinCondition()
        {
            for (var y = 0; y < GridSize; y++)
            {
                var board = new Board(GridSize);
                FillRow(board, y);

                Assert.True(BoardEvaluator.HasWinningRow(board));
            }
        }
        public void TestCompeteWorksWithProbabilisticStates()
        {
            var engine     = Connect4TestUtils.GetSearchEngine(1, ParallelismMode.FirstLevelOnly);
            var startState = new StartState(new Connect4State(Connect4TestUtils.GetEmptyBoard(), Player.Max));

            var results = engine.Compete(startState, 3, (s, d, l) => 0);

            var finalState = (ProbabilisticConnect4State)results.FinalState;

            Assert.IsTrue(BoardEvaluator.IsWin(finalState.Board, Player.Min), "Min should have won; Final state is " + Environment.NewLine + finalState);
        }
Exemple #10
0
 // Use this for initialization
 public Core(BoardManager board_manager, Referee referee)
 {
     this.board_evaluator = new BoardEvaluator();
     this.board_manager   = board_manager;
     this.referee         = referee;
     this.root            = new Node();
     this.root.board      = 0;
     this.board_manager.create(0);
     this.root_team   = Piece.Team.NULL;
     this.index_board = 1;
     this.is_thinking = false;
     this.is_stopped  = false;
     this.ai_thread   = null;
 }
        public void IsTie_OnFullBoard_WithNoWinCondition()
        {
            var board = new Board(GridSize);

            board.SetCell(0, 0, CellState.O);
            board.SetCell(1, 0, CellState.X);
            board.SetCell(2, 0, CellState.O);
            board.SetCell(0, 1, CellState.O);
            board.SetCell(1, 1, CellState.X);
            board.SetCell(2, 1, CellState.X);
            board.SetCell(0, 2, CellState.X);
            board.SetCell(1, 2, CellState.O);
            board.SetCell(2, 2, CellState.X);

            Assert.True(BoardEvaluator.IsTie(board));
        }
        public void HasWinningDiagonal_ForDiagonals_WithWinCondition()
        {
            // Top left to bottom right
            {
                var board = new Board(GridSize);
                for (var xy = 0; xy < GridSize; xy++)
                {
                    board.SetCell(xy, xy, CellState.X);
                }

                Assert.True(BoardEvaluator.HasWinningDiagonal(board));
            }

            // Bottom left to top right
            {
                var board = new Board(GridSize);
                for (var xy = 0; xy < GridSize; xy++)
                {
                    board.SetCell(xy, GridSize - 1 - xy, CellState.X);
                }

                Assert.True(BoardEvaluator.HasWinningDiagonal(board));
            }
        }