Esempio n. 1
0
    //-----------------------------inits are below, these could be overloaded...------------------------------------
    /// <summary>
    /// This is the main intended interface for Decider, make a new one! based on the current one's properties.
    /// </summary>
    /// <param name="move">this must be in the Choices.Key property</param>
    /// <returns>a new Decider, for sweet saftey and functionality</returns>
    public Decider Pick(Move move)
    {
        DeciderNode node = (DeciderNode)root.to[move];

        root.ConvertToTuber();
        return(new Decider(node));
    }
Esempio n. 2
0
 //this is for internal Deciderness.
 public Decider(DeciderNode node)
 {
     root = node;
     if (root.IsLeaf)
     {
         root.SetMovesTo();
     }
 }
Esempio n. 3
0
    //TODO make N deep
    public Move TwoDeep()
    {
        Debug.Log("two deep picker");
        IDictionary <DeciderNode, Empty> checkList = new Dictionary <DeciderNode, Empty>(10000);
        ICollection <ITraversable>       nodes     = root.ToNodes();

        foreach (DeciderNode node in nodes)
        {
            checkList.Add(node, new Empty());
        }

        foreach (DeciderNode node in nodes)
        {
            node.AddAndCreateAllUniqueChildrenAgainstChecklist(checkList, 2);
        }
        DeciderNode bestNode = new DeciderNode(SmartSquare.StandardBoardSetUp());

        int best = int.MaxValue;

        if (root.Player)
        {
            foreach (ITraversable child in nodes)
            {
                DeciderNode testChild = (DeciderNode)child;
                int         score     = testChild.ScoreForBranch();


                if (score < best)
                {
                    best     = score;
                    bestNode = testChild;
                }
            }
        }
        else
        {
            best = int.MinValue;

            foreach (ITraversable child in nodes)
            {
                DeciderNode testChild = (DeciderNode)child;
                int         score     = testChild.ScoreForBranch();


                if (score > best)
                {
                    best     = score;
                    bestNode = testChild;
                }
            }
        }

        return(bestNode.board.moveToMakeThis);//TODO this will return null
    }
Esempio n. 4
0
    private Move MoveForNode(DeciderNode node)
    {
        DeciderNode check = node;

        while (check.From() != null)
        {
            if ((DeciderNode)check.From() == root)
            {
                return(check.board.moveToMakeThis);
            }
            check = (DeciderNode)check.From();
        }
        return(node.board.moveToMakeThis);
    }
Esempio n. 5
0
    public Move OneDeep()
    {
        Debug.Log("one deep picker");
        ICollection <ITraversable> nodes = root.ToNodes();

        foreach (DeciderNode node in nodes)
        {
            node.SetMovesTo();
        }
        nodes = root.ToNodes();
        DeciderNode bestNode = new DeciderNode(SmartSquare.StandardBoardSetUp());

        int best = int.MinValue;

        if (!root.Player)
        {
            foreach (ITraversable child in nodes)
            {
                DeciderNode testChild = (DeciderNode)child;
                int         score     = testChild.BestMoveScore();


                if (score > best)
                {
                    best     = score;
                    bestNode = testChild;
                }
            }
        }
        else
        {
            best = int.MaxValue;
            foreach (ITraversable child in nodes)
            {
                DeciderNode testChild = (DeciderNode)child;
                int         score     = testChild.BestMoveScore();


                if (score < best)
                {
                    best     = score;
                    bestNode = testChild;
                }
            }
        }

        return(bestNode.board.moveToMakeThis);
    }
Esempio n. 6
0
    private Move StupidHeapBuild()
    {
        Debug.Log("picking one");
        IDictionary <DeciderNode, Empty> nodesInTree = new Dictionary <DeciderNode, Empty>(10000);


        MaxHeap heap = new MaxHeap(root);

        Debug.Log("adding nodes to checklist");
        root.AddNodesToTreeRecursivly(nodesInTree);

        if (root.to.Keys == null)
        {
            return(null);
        }
        Debug.Log("popping and adding to tree");
        while (nodesInTree.Count < 10000 && heap.HasTop())
        {
            DeciderNode top = (DeciderNode)heap.Pop();


            top.SetMovesTo();
            foreach (DeciderNode node in top.to.Values)
            {
                if (!nodesInTree.ContainsKey(node))
                {
                    heap.AddToHeap(node);
                    nodesInTree.Add(node, new Empty());
                }
            }
        }
        Debug.Log(heap.Count);
        // picking the best for the player;

        DeciderNode topOfHeap = (DeciderNode)heap.Pop();

        while (topOfHeap.Player != root.Player && heap.HasTop())
        {
            topOfHeap = (DeciderNode)heap.Pop();
        }

        return(MoveForNode(topOfHeap));
    }
Esempio n. 7
0
    public void RobinHoodEditTestsSimplePasses()
    {
        Debug.Log("Robin Hood Tests");

        int size = 10;

        IDictionary <string, bool> RH = new RobinHoodDictionary <string, bool>(100000);


        string str = "a";

        for (int i = 0; i < size; i++)
        {
            RH.Add(str, false);
            str = str + "b";
        }
        Assert.True(RH.ContainsKey("a"));
        Debug.Log(RH.Count);
        Assert.True(size == RH.Count);

        DeciderNode node    = new DeciderNode(SmartSquare.StandardBoardSetUp());
        DeciderNode node2   = new DeciderNode(SmartSquare.StandardBoardSetUp());
        DeciderNode badNode = new DeciderNode(SmartSquare.NotStandardBoardSetUp());

        IDictionary <DeciderNode, Empty> game = new RobinHoodDictionary <DeciderNode, Empty>(1000);



        game.Add(node, new Empty());
        //test that the hash override works
        Assert.True(game.ContainsKey(node2));


        //that doesn't contain bad node
        Assert.False(game.ContainsKey(badNode));

        game.Add(badNode, new Empty());

        //that it does
        Assert.True(game.ContainsKey(badNode));
        //count is 2
        Assert.True(game.Count == 2);
    }
Esempio n. 8
0
    public void ChessGameTestsSimplePasses()
    {
        SmartSquare[,] dumbSquares = SmartSquare.StandardBoardSetUp();

        Decider game = new Decider(dumbSquares);

        int choices = game.Choices().Count;

        Debug.Log(choices);


        DeciderNode node = new DeciderNode(SmartSquare.StandardBoardSetUp());

        node.SetMovesTo();

        Debug.Log(node.to.Count);
        //TestPickOneForMe();

        //PlayGame(10);
    }
Esempio n. 9
0
 /// <summary>
 /// This is for setting up. don't feed a game in progress here, it will destroy the whole tree!
 /// </summary>
 /// <param name="setupState"></param>
 public Decider(SmartSquare[,] setupState)
 {
     root = new DeciderNode(setupState);
     root.SetMovesTo();//first player
     //we know this is a leaf
 }