Ejemplo n.º 1
0
        public Board(Board b)
        {
            Type = b.Type;
            Pieces = new Tile[b.NumRows,b.NumCols];

            for (int i = 0; i < NumRows; i++)
            {
                for (int j = 0; j < NumCols; j++)
                {
                    Pieces[i,j] = new Tile(b.Pieces[i,j]);
                }
            }
        }
Ejemplo n.º 2
0
        private ABStruct MinValue(Board state, int a, int b, int expand)
        {
            var abst = new ABStruct() {val = 1, move = null, depth = expand};
            var moves = state.GetPossibleMoves(TileState.White);
            if (!moves.Any())
                return abst;
            var v = 1;
            expand --;
            if (expand > 0)
            {
                foreach (var move in moves)
                {
                    var result = new Board(state);
                    result.MovePiece(move.startTile, GameBoard.GetTileInDirection(move.startTile, move.direction));

                    if (move.CapturedTiles.Keys.Any())
                    {
                        foreach (var dir in move.CapturedTiles.Keys)
                        {
                            result.MakeMove(move, dir);
                            move.captureDirection = dir;

                            numNodes++;
                            abst = MaxValue(result, a, b, expand);
                            abst.move = move;
                            v = Math.Min(v, abst.val);
                            if (v <= a)
                            {
                                minPrunes++;
                                return abst;
                            }
                            b = Math.Min(b, v);
                        }

                    }
                    else
                    {
                        numNodes++;
                        abst = MaxValue(result, a, b, expand);
                        abst.move = move;
                        v = Math.Min(v, abst.val);
                        if (v <= a)
                        {
                            minPrunes++;
                            return abst;
                        }
                        b = Math.Min(b, v);
                    }

                }
            }
            else
            {
                abst.move = moves.First();
                //abst.val =
                abst.cutOff = true;
            }
            return abst;
        }
Ejemplo n.º 3
0
        /*
         * 3x3:
         *  easy - 480 x 215 -- 560 x 250 (80px x 35px)
         *  med -  480 x 250 -- 560 x 285
         *  hard - 480 x 285 -- 560 x 320
         *
         * 5x5:
         *  easy - 480 x 390 -- 560 x 425
         *  med -  480 x
        */
        private void MenuButtonSelect(int x, int y)
        {
            if (ClickedOnButton(x, y))
            {
                for(int b = 0; b < BOARDS; b++)
                {
                    for (int d = 0; d < DIFFS; d++)
                    {
                        if (y < buttonY[b] + (d+1)*buttonHeight)
                        {
                            var bt = (BoardType) Enum.GetValues(typeof (BoardType)).GetValue(b);
                            GameBoard = new Board(bt);
                            GameDifficulty = (Difficulty)Enum.GetValues(typeof(Difficulty)).GetValue(d);

                            InitializeGameStateVars();

                            switch (GameBoard.Type)
                            {
                                case BoardType.Three:
                                    boardToUse = boardThree;
                                    break;
                                case BoardType.Five:
                                    boardToUse = boardFive;
                                    break;
                            }
                            return;
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Performs an AlphaBeta Search with a given state and cut-off value.
 /// </summary>
 /// <param name="state">A copy of the current game board state</param>
 /// <param name="expand">The max number of depths to go through</param>
 /// <returns></returns>
 private Board.Move AlphaBetaSearch(Board state, int expand)
 {
     numNodes = 0;
     // 1 = black wins, -1 = black loses
     var v = MaxValue(state, -1, 1, expand);
     Console.WriteLine("1. Cutoff: " + (v.cutOff));
     Console.WriteLine("2. Max Depth: " + ((int)GameDifficulty*D - (v.depth)));
     Console.WriteLine("3. Total number of nodes: " + numNodes);
     Console.WriteLine("5. NumPrunes-Min: " + minPrunes);
     Console.WriteLine("6. NumPrunes-Max: " + maxPrunes);
     return v.move;
 }