示例#1
0
    public int getMove(GameCollection games, Moves pMoves, Moves cMoves, Moves av)
    {
        Random      r      = new Random();
        Moves       finalM = new Moves();
        IsAvailable iA     = new IsAvailable(av);

        /*
         * ####################################################################
         * ####################################################################
         * ####################################################################
         */
        if (cMoves.getMoves().Length + pMoves.getMoves().Length == 0) // Console.WriteLine("### 000 ###");
        {
            Moves z = games.toMoveMap();
            for (int i = 0; i < 300; i++)
            {
                int mySelection = z.getMoves()[r.Next(z.getMoves().Length)];
                if (iA.check(mySelection))
                {
                    Console.WriteLine("selected move: " + mySelection);
                    return(mySelection);
                }
                if (i >= 299)
                {
                    Console.WriteLine("giving up");
                }
            }
        }

        /*
         * ####################################################################
         * ####################################################################
         * ####################################################################
         */

        if (cMoves.getMoves().Length == 0 && pMoves.getMoves().Length == 1) // Console.WriteLine("### 001 ###");
        {
            GameCollection mm = new GameCollection();

            int theMove;
            theMove = pMoves.getMoves()[0];

            Index myIdenx = games.getIndexGameContains(theMove);

            Console.WriteLine("index -> " + myIdenx);
            Console.WriteLine("games -> " + games);

            bool skip = false;

            for (int i = 0; i < games.getSize(); i++)
            {
                for (int j = 0; j < myIdenx.getSize(); j++)
                {
                    if (i == myIdenx.getIndexArray()[j])
                    {
                        skip = true;
                    }
                }
                if (skip)
                {
                    skip = false; continue;
                }
                mm.addGame(games.getGame(i));
            }

            Console.WriteLine("selection -> " + mm);

            Moves z = mm.toMoveMap();
            for (int i = 0; i < 300; i++)
            {
                int mySelection = z.getMoves()[r.Next(z.getMoves().Length)];
                if (iA.check(mySelection))
                {
                    Console.WriteLine("selected move: " + mySelection);
                    return(mySelection);
                }
                if (i >= 299)
                {
                    Console.WriteLine("giving up");
                }
            }
        }

        /*
         * ####################################################################
         * ####################################################################
         * ####################################################################
         */

        if (cMoves.getMoves().Length + pMoves.getMoves().Length >= 3) // Console.WriteLine("### 002 ###");
        {
            Gen lol = new Gen();

            GameCollection p = new GameCollection();
            GameCollection c = new GameCollection();

            GameCollection playerSelection   = new GameCollection();
            GameCollection computerSelection = new GameCollection();

            lol.combinations(pMoves.getMoves(), p);
            lol.combinations(cMoves.getMoves(), c);

            Console.WriteLine("player combination: " + p);
            Console.WriteLine("computer combination: " + c);

            // combinacoes prontas, pesquisar jogos
            for (int i = 0; i < p.getSize(); i++)
            {
                int myIdenx = games.getIndexGameContains(p.getGame(i).getGameArray()[0], p.getGame(i).getGameArray()[1]);

                if (myIdenx != -1)
                {
                    playerSelection.addGame(games.getGame(myIdenx));
                }
            }

            for (int i = 0; i < c.getSize(); i++)
            {
                int myIdenx = games.getIndexGameContains(c.getGame(i).getGameArray()[0], c.getGame(i).getGameArray()[1]);

                if (myIdenx != -1)
                {
                    computerSelection.addGame(games.getGame(myIdenx));
                }
            }

            Console.WriteLine("playerSelection = " + playerSelection);
            Console.WriteLine("computerSelection = " + computerSelection);

            Console.WriteLine("playerSelection.toMoveArray = " + playerSelection.toMoveArray());
            Console.WriteLine("computerSelection.toMoveArray = " + computerSelection.toMoveArray());

            if (computerSelection.getSize() > 0)
            {
                for (int i = 0; i < computerSelection.toMoveArray().getMoves().Length; i++)
                {
                    int mySelection = computerSelection.toMoveArray().getMoves()[i];
                    Console.WriteLine("computer iA.check -> " + iA.check(mySelection));
                    Console.WriteLine("mySelection -> " + mySelection);
                    if (iA.check(mySelection))
                    {
                        return(mySelection);
                    }
                }
            }

            if (playerSelection.getSize() > 0)
            {
                for (int i = 0; i < playerSelection.toMoveArray().getMoves().Length; i++)
                {
                    int mySelection = playerSelection.toMoveArray().getMoves()[i];
                    Console.WriteLine("player iA.check -> " + iA.check(mySelection));
                    Console.WriteLine("mySelection -> " + mySelection);
                    if (iA.check(mySelection))
                    {
                        return(mySelection);
                    }
                }
            }
            else
            {
                Console.WriteLine("foideus");
            }

            /*
             * for (int i = 0; i < computerSelection.toMoveArray().getMoves().Length; i++)
             * {
             * int mySelection = computerSelection.toMoveArray().getMoves()[i];
             * if (iA.check(mySelection))
             * {
             * return mySelection;
             * }
             * }
             */
        }

        Console.WriteLine("tudo errado.");

        /*
         * ####################################################################
         * ####################################################################
         * ####################################################################
         */

        if (true) // last resort
        {
            GameCollection mm = new GameCollection();

            int theMove;
            theMove = cMoves.getMoves()[0];

            Index myIdenx = games.getIndexGameContains(theMove);

            Console.WriteLine("index -> " + myIdenx);
            Console.WriteLine("games -> " + games);

            for (int i = 0; i < games.getSize(); i++)
            {
                for (int j = 0; j < myIdenx.getSize(); j++)
                {
                    if (i == myIdenx.getIndexArray()[j])
                    {
                        mm.addGame(games.getGame(i));
                    }
                }
            }

            Console.WriteLine("selection -> " + mm);

            Moves z = mm.toMoveMap();
            for (int i = 0; i < 300; i++)
            {
                int mySelection = z.getMoves()[r.Next(z.getMoves().Length)];
                if (iA.check(mySelection))
                {
                    Console.WriteLine("selected move: " + mySelection);
                    return(mySelection);
                }
                if (i >= 299)
                {
                    Console.WriteLine("giving up");
                }
            }
        }
        // real last resort
        if (true)
        {
            GameCollection mm = new GameCollection();
            Console.WriteLine("Last Resort");
            Console.WriteLine("Available moves -> " + av);
            Console.WriteLine("Games -> " + games);
            Console.WriteLine("cMoves -> " + cMoves);
            Console.WriteLine("pMoves -> " + pMoves);

            GameCollection gaminhoLastResourt = new GameCollection();
            GameCollection pGames             = new GameCollection();

            for (int i = 0; i < cMoves.getMoves().Length; i++)
            {
                Index holyDog = games.getIndexGameContains(cMoves.getMoves()[i]);
                for (int j = 0; j < holyDog.getIndexArray().Length; j++)
                {
                    gaminhoLastResourt.addGame(games.getGame(holyDog.getIndexArray()[j]));
                }
            }

            Console.WriteLine("gaminho -> " + gaminhoLastResourt.toMoveArray());

            if (gaminhoLastResourt.getSize() > 0)
            {
                for (int i = 0; i < gaminhoLastResourt.toMoveArray().getMoves().Length; i++)
                {
                    int mySelection = gaminhoLastResourt.toMoveArray().getMoves()[i];
                    Console.WriteLine("player iA.check -> " + iA.check(mySelection));
                    Console.WriteLine("mySelection -> " + mySelection);
                    if (iA.check(mySelection))
                    {
                        return(mySelection);
                    }
                }
            }
            else
            {
                Console.WriteLine("foideus de novo, #semata");
            }
        }
        return(-1);
    }
示例#2
0
    public bool addMove(int square, int player)
    {
        if (square == -1)
        {
            return(false);
        }

        IsAvailable iA   = new IsAvailable(availableMoves);
        bool        test = iA.check(square);

        if (test == false)
        {
            return(false);
        }

        /*
         * ################################################################
         * ################################################################
         */

        if ((playerStarts && player == 1) || (!playerStarts && player == 2))
        {
            pMoves.add(square);
            availableMoves.remove(square);
            mp.Play();
            if (!testBictory())
            {
                setStatus(Status.Computer);
            }
        }
        if ((playerStarts && player == 2) || (!playerStarts && player == 1))
        {
            cMoves.add(square);
            availableMoves.remove(square);
            mp.Play();
            if (!testBictory())
            {
                setStatus(Status.Player);
            }
        }

        /*
         * ################################################################
         * ################################################################
         */

        instance = ink.Instance() as RigidBody2D;

        if (player == 1)
        {
            instance.GetNode <Sprite>("Cray").Texture  = player1List[rand.Next(5)];
            instance.GetNode <Sprite>("Cray").Scale    = new Vector2(0.3f, 0.3f);
            instance.GetNode <Sprite>("Cray").Position = squareToCoords(square);
        }
        else
        {
            instance.GetNode <Sprite>("Cray").Texture  = player2List[rand.Next(5)];
            instance.GetNode <Sprite>("Cray").Scale    = new Vector2(0.25f, 0.25f);
            instance.GetNode <Sprite>("Cray").Position = squareToCoords(square);
        }
        AddChild(instance);
        squareList.Add(instance);

        return(true);
    }