Esempio n. 1
0
        public override string Turn(Game current)
        {
            String returnString = "Pass";

            Tile t1 = new Tile(current.ReturnTile(0));
            Tile t2 = new Tile(current.ReturnTile(1));
            Tile t3 = new Tile(current.ReturnTile(2));


            Tile[] options     = new Tile[] { t1, t2, t3 };
            bool[] canBePlaced = new bool[] { false, false, false };


            for (int i = 0; i < 3; i++) // ugly brute force check that a tile can be placed
            {
                if (options[i].ReturnCost() < this.GetButtons())
                {
                    for (int r = 0; r < 4; r++)
                    {
                        for (int x = -1; x < 10; x++)
                        {
                            for (int y = -1; y < 10; y++)
                            {
                                if (this.GetGrid().tryTile(x, y, options[i]))
                                {
                                    canBePlaced[i] = true;
                                    goto NextTile;
                                }
                            }
                        }
                        options[i].rotate(1);
                    }
                }
                NextTile :;
            }

            PlayerAgentPointPerTimeReactiveSO oppC = new PlayerAgentPointPerTimeReactiveSO(current.ReturnOpponent(this.GetName()));//get opponent
            //use innerturn to get reactive values and ajust for this



            //determine what tile to place
            int numCanBePlaced = 0;
            int toBePlaced     = -1;

            foreach (bool b in canBePlaced)
            {
                if (b)
                {
                    numCanBePlaced++;
                }
            }

            switch (numCanBePlaced)
            {
            case 0:
                return(returnString);

            case 1:
                int i = 0;
                foreach (bool b in canBePlaced)
                {
                    if (b)
                    {
                        toBePlaced = i;
                    }
                    i++;
                }
                break;

            case 2:    //if more than 1 choice then ppt
            case 3:
                int   j     = 0;
                float bestb = -80;
                float c;
                foreach (bool b in canBePlaced)
                {
                    if (b)
                    {
                        c = 0;
                        foreach (bool t in options[j].returnshape())    //points for tile size
                        {
                            if (t)
                            {
                                c += 2;
                            }
                        }
                        c += options[j].ReturnButtons() * current.ButtonsLeft(this.GetTime()); //points for the buttons
                        c -= options[j].ReturnCost();                                          //cost
                        c  = c / options[j].ReturnTime();

                        if (oppC.GetTime() < this.GetTime() - options[j].ReturnTime())
                        {
                            c += 1;
                        }

                        c -= oppC.OppChoice(current, j + 1);


                        if (c > bestb)
                        {
                            toBePlaced = j;
                            bestb      = c;
                        }
                    }
                    j++;
                }
                break;

            default:
                Console.WriteLine("error");
                Console.ReadLine();
                break;
            }

            t1      = new Tile(current.ReturnTile(0));//reset tile manipulations
            t2      = new Tile(current.ReturnTile(1));
            t3      = new Tile(current.ReturnTile(2));
            options = new Tile[] { t1, t2, t3 };



            float co = 0; //points for tile size

            foreach (bool t in options[toBePlaced].returnshape())
            {
                if (t)
                {
                    co += 2;
                }
            }

            if (oppC.GetTime() > this.GetTime() - options[toBePlaced].ReturnTime()) //if opponent would get the next turn
            {
                if (1 - oppC.OppChoice(current, 0)                                  //if passing is worth more than the tile considering opponents move
                    >
                    ((options[toBePlaced].ReturnButtons() * current.ButtonsLeft(this.GetTime()) - (options[toBePlaced].ReturnCost()) + (co)) / options[toBePlaced].ReturnTime())
                    - oppC.OppChoice(current, toBePlaced + 1)
                    )
                {
                    return("Pass");
                }
            }
            else
            {
                if (1 >//if passing is worth more than the tile
                    ((options[toBePlaced].ReturnButtons() * current.ButtonsLeft(this.GetTime()) - (options[toBePlaced].ReturnCost()) + (co)) / options[toBePlaced].ReturnTime())
                    )
                {
                    return("Pass");
                }
            }



            //place that tile (more ugly brute force)


            int best = 0;

            List <Tile> tiles = current.GetTileList();

            for (int r = 0; r < 4; r++)
            {
                for (int x = -1; x < 10; x++)
                {
                    for (int y = -1; y < 10; y++)
                    {
                        if (this.GetGrid().tryTile(x, y, options[toBePlaced]))
                        {
                            //returnString = toBePlaced + "/" + y + "/" + x + "/R" + r;


                            Grid g = new Grid(this.GetGrid());

                            g.addTile(x, y, options[toBePlaced]);//check x and y
                            int bestL = 0;

                            foreach (Tile t in tiles)
                            {
                                if (CanBePlaced(t, g))
                                {
                                    bestL++;
                                }
                            }

                            if (best < bestL)
                            {
                                best         = bestL;
                                returnString = toBePlaced + "/" + y + "/" + x + "/R" + r;
                            }
                        }
                    }
                }
                options[toBePlaced].rotate(1);
            }



            return(returnString);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\Data\" + "1.txt";

            Player pass = new Player("Passer");
            Player hum1 = new PlayerHuman("Human 1");
            Player hum2 = new PlayerHuman("Human 2");

            Player spaceOptimization = new PlayerAgentSpaceOptimization("SpaceOptimization");
            Player sevenPoints       = new PlayerAgentSevenPoint("SevenPoints");

            Player first = new PlayerAgentFirstOptionSO("First");
            Player high  = new PlayerAgentHighestPointSO("Highest");
            Player pPT   = new PlayerAgentPointPerTimeSO("PPT");
            PlayerAgentEarlyEconomySO eco = new PlayerAgentEarlyEconomySO("Economy");

            eco.TimeThreshhold = 34;
            Player react = new PlayerAgentPointPerTimeReactiveSO("React");

            Player highSP = new PlayerAgentHighestPointSP("HighestSP");

            Player[] playerList = { pass,              hum1, hum2,  //base
                                    spaceOptimization, sevenPoints, //placement
                                    first,             high, pPT,eco, react,//SO
                                    highSP                          //SP
            };



            Player p1 = spaceOptimization;
            Player p2 = sevenPoints;


            while (true)
            {
                Console.Clear();
                Console.WriteLine("Patchwork Experimentor");
                Console.WriteLine("");
                Console.WriteLine("P1: " + p1.GetName());
                Console.WriteLine("P2: " + p2.GetName());
                Console.WriteLine("");
                Console.WriteLine("1 - Generate New Setup");
                Console.WriteLine("2 - Set Player1");
                Console.WriteLine("3 - Set Player2");
                Console.WriteLine("4 - Set Economy Threshhold");
                Console.WriteLine("5 - Play Single Game");
                Console.WriteLine("6 - Play 1000 Games");
                Console.WriteLine("");
                Console.WriteLine("please enter the demo you would like to run.");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");


                switch (Console.ReadLine())
                {
                case "1":
                    Console.Clear();
                    Console.WriteLine("Generating Setups");
                    filemaker();
                    break;

                case "2":
                    p1 = Select(playerList);
                    break;

                case "3":
                    p2 = Select(playerList);
                    break;

                case "4":
                    eco.TimeThreshhold = Convert.ToInt32(Console.ReadLine());
                    break;

                case "5":
                    Console.Clear();
                    p1.Reset();
                    p2.Reset();
                    Game game1 = new Game();
                    tilesLoadFile(game1, path);
                    game1.setPlayers(p1, p2);
                    Console.WriteLine("Winner: " + game1.rungame().GetName());
                    Console.ReadLine();
                    break;

                case "6":
                    Console.Clear();
                    int Countp1 = 0;
                    int Countp2 = 0;


                    for (int i = 0; i < 500; i++)
                    {
                        p1.Reset();
                        p2.Reset();
                        Game   game2 = new Game();
                        string path2 = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\Data\RandomSetup" + i + ".txt";
                        tilesLoadFile(game2, path2);
                        game2.setPlayers(p1, p2);

                        string winner = game2.rungame().GetName();

                        if (winner == p1.GetName())
                        {
                            Countp1++;
                        }
                        if (winner == p2.GetName())
                        {
                            Countp2++;
                        }

                        Console.WriteLine(i + ":" + winner);
                    }

                    for (int i = 500; i < 1000; i++)    //for second half of games invert who goes first
                    {
                        p1.Reset();
                        p2.Reset();
                        Game   game2 = new Game();
                        string path2 = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\Data\RandomSetup" + i + ".txt";
                        tilesLoadFile(game2, path2);
                        game2.setPlayers(p2, p1);

                        string winner = game2.rungame().GetName();

                        if (winner == p1.GetName())
                        {
                            Countp1++;
                        }
                        if (winner == p2.GetName())
                        {
                            Countp2++;
                        }
                        if (winner == "Draw")
                        {
                        }

                        Console.WriteLine(i + ":" + winner);
                    }



                    Console.WriteLine(p1.GetName() + " " + Countp1 + " Wins");
                    Console.WriteLine(p2.GetName() + " " + Countp2 + " Wins");
                    Console.ReadLine();
                    break;

                case "7":

                    break;

                default:
                    break;
                }
            }
        }