Ejemplo n.º 1
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;
        }