예제 #1
0
    private static void MoveTypeHandle(Move move, SmartSquare[,] board)
    {
        // Debug.Log()
        switch (move.moveType)
        {
        case MoveType.CastleLong:
            if (move.from.row == 7)
            {
                board[7, 3] = board[7, 0];
                board[7, 0] = new SmartSquare(true, Token.None);
            }
            else
            {
                board[0, 3] = board[0, 0];
                board[0, 0] = new SmartSquare(true, Token.None);
            }
            return;

        case MoveType.CastleShort:
            if (move.from.row == 7)
            {
                board[7, 5] = board[7, 7];
                board[7, 7] = new SmartSquare(true, Token.None);
            }
            else
            {
                board[0, 5] = board[0, 7];
                board[0, 7] = new SmartSquare(true, Token.None);
            }
            return;
        }
    }
예제 #2
0
    private static void TestPickOneForMe()
    {
        SmartSquare[,] dumbSquares = SmartSquare.StandardBoardSetUp();

        Decider game = new Decider(dumbSquares);

        game = game.Pick(game.PickOneForMe());
    }
예제 #3
0
    //---------------toggle computer above-----------------

    //-----------------on start up stuff below, also SyncWithGame----------------------------
    /// <summary>
    /// refresh button calls this
    /// </summary>
    public void SetUpNewGame()
    {
        Debug.Log("Setting up new Game");
        CurrentPlayer = player1;
        game          = new Decider(SmartSquare.StandardBoardSetUp());
        SetComputerPlayerIcon();
        SetComputerIcon();
        SyncWithGame();
    }
예제 #4
0
파일: Decider.cs 프로젝트: AndrewPool/Chess
    //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
    }
예제 #5
0
    private static void PlayGame(int turns)
    {
        SmartSquare[,] dumbSquares = SmartSquare.StandardBoardSetUp();

        Decider game = new Decider(dumbSquares);

        int turnCount = turns;

        while (turnCount > 0)
        {
            game = game.Pick(game.PickOneForMe());
            turnCount--;
        }
    }
예제 #6
0
파일: Decider.cs 프로젝트: AndrewPool/Chess
    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);
    }
예제 #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);
    }
예제 #8
0
    private void PerformHashTests()
    {
        ChessBoard startingBoard1 = new ChessBoard(SmartSquare.StandardBoardSetUp());
        ChessBoard startingBoard2 = new ChessBoard(SmartSquare.StandardBoardSetUp());

        //changed pieces
        ChessBoard notStartingBoard  = new ChessBoard(SmartSquare.NotStandardBoardSetUp());
        ChessBoard notStartingBoard2 = new ChessBoard(SmartSquare.NotStandardBoardSetUp2());
        ChessBoard notStartingBoard3 = new ChessBoard(SmartSquare.NotStandardBoardSetUp3());
        ChessBoard notStartingBoard4 = new ChessBoard(SmartSquare.NotStandardBoardSetUp4());

        //pieces not there
        ChessBoard notStartingBoard5 = new ChessBoard(SmartSquare.NotStandardBoardSetUp5());
        ChessBoard notStartingBoard6 = new ChessBoard(SmartSquare.NotStandardBoardSetUp6());

        //visualize the tests
        Debug.Log(startingBoard1.Hash);
        Debug.Log(notStartingBoard.Hash);
        Debug.Log(notStartingBoard2.Hash);
        Debug.Log(notStartingBoard3.Hash);
        Debug.Log(notStartingBoard4.Hash);
        Debug.Log(notStartingBoard5.Hash);
        Debug.Log(notStartingBoard6.Hash);

        //the board is the board
        Assert.IsTrue(startingBoard1.Hash == startingBoard2.Hash);

        //not starting board is not the board
        Assert.False(startingBoard1.Hash == notStartingBoard.Hash);

        Assert.False(startingBoard1.Hash == notStartingBoard2.Hash);

        Assert.False(startingBoard1.Hash == notStartingBoard3.Hash);

        Assert.False(startingBoard1.Hash == notStartingBoard4.Hash);


        //not stating board is also not other not the starting board
        Assert.False(notStartingBoard.Hash == notStartingBoard2.Hash);
        //missing pieces testing
        Assert.False(notStartingBoard5.Hash == notStartingBoard6.Hash);
    }
예제 #9
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);
    }