Exemple #1
0
        public static void Main(string[] args)
        {
            Printer.Start();
            Printer.AddToPrinter("Hello World");
            var board = new Board();

            board.PrintBoardToPrinter();
            PlayerAbstract white       = new RandomAI(board, Color.White);
            PlayerAbstract black       = new AlphaBetaSimple(board, Color.Black);
            var            gamesResult = GameLoop.Games(board, white, black, 1, boardPrint: true);
            var            count       = gamesResult.Length;

            Printer.AddToPrinter("Number of games played: " + count);
            var tmp = gamesResult.Count(a => a.Item1 == Color.Black);

            Printer.AddToPrinter(tmp + " wins for black (" + tmp / (double)count * 100d + "%) (" + black.Name + ")");
            tmp = gamesResult.Count(a => a.Item1 == Color.White);
            Printer.AddToPrinter(tmp + " wins for white (" + tmp / (double)count * 100d + "%) (" + white.Name + ")");
            tmp = gamesResult.Count(a => a.Item1 == Color.NoColor);
            Printer.AddToPrinter(tmp + " draws (" + tmp / (double)count * 100d + "%)");
            Printer.AddToPrinter(gamesResult.Average(a => a.Item2) + " average number of turns needed");
            Printer.AddToPrinter(
                gamesResult.Average(a => a.Item3) + "ms need on average for white (" + white.Name + ")");
            Printer.AddToPrinter(
                gamesResult.Average(a => a.Item4) + "ms need on average for black (" + black.Name + ")");

            Thread.Sleep(1000);
            Console.ReadLine();
        }
        public void TenThousandRandomGames()
        {
            const int numberOfGames = 10000;
            Player    p1            = new RandomAI(Color.White);
            Player    p2            = new RandomAI(Color.Black);
            Game      game          = new Game('c', 'g', p1, p2);

            //watch.Start();
            for (int i = 0; i < numberOfGames; i++)
            {
                while (!game.IsFinished)
                {
                    game.ApplyMove(game.CurrentPlayer.ProduceMove());
                }
                game = new Game('c', 'g', p1, p2);
            }
        }
        private void SetUpGame(char whiteGap, char blackGap, bool userPlaysWhite)
        {
            Core.Color userColor = userPlaysWhite ? Core.Color.White : Core.Color.Black;
            m_ControlEnabled     = m_BoardRotated = userPlaysWhite;
            m_User               = new HumanPlayer(userColor);
            m_User.TurnTaken    += EnableControl;
            m_User.MoveProduced += DisableControl;
            Player opponent;

            if (m_LocalMultiplayer)
            {
                opponent = new HumanPlayer(userColor.Inverse());
            }
            else
            {
                opponent = new RandomAI(userColor.Inverse());
            }
            m_GameManager           = new GameManager(whiteGap, blackGap, m_User, opponent);
            m_GameManager.MoveMade += RenderAllPawns;
        }
Exemple #4
0
        public static void Run(int size, int iterations, string simDesc, string boardPath, bool dbInsert)
        {
            Statistics stats = new Statistics(new Simulation()
            {
                SimulationId = Guid.NewGuid(), Description = simDesc, SimulationDate = DateTime.Now, AIType = (int)AIType.Random
            });

            try
            {
                Random random = new Random();
                for (int i = 0; i < iterations; i++)
                {
                    Game game = new Game();
                    game.GameId       = Guid.NewGuid();
                    game.SimulationId = stats.Simulation.SimulationId;
                    game.GameNumber   = i + 1;


                    string   s      = Files.Read(boardPath);
                    Board    board  = GridParser.Parse(s, size);
                    RandomAI RandAI = new RandomAI(board, game.GameId, random);
                    stats.Shots.AddRange(RandAI.Play());
                    stats.Games.Add(game);
                    // Display.Grid(board);
                }

                if (dbInsert)
                {
                    DbInsert.Insert(stats);
                }
                Console.WriteLine("Done");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Rock Paper Sciscors!");


            //TODO: pull out into function
            // - - - choose your cpu - - - //
            //get input
            string input = null;

            while (!validateAiInput(input, AINames))
            {
                Console.WriteLine("Choose the AI to play against:");
                Console.WriteLine("Random - Randomly chooses moves.");
                Console.WriteLine("Smart - takes into account some information");
                input = Console.ReadLine();
                input = input.Trim().ToLower();
            }

            //use input
            IAI gameai;

            switch (input)
            {
            case ("random"):
                gameai = new RandomAI();
                break;

            case ("smart"):
                gameai = new SmarterAI();
                break;

            default:
                Debug.WriteLine("Warning, unknown input made it through the AI choice input validation");
                gameai = new RandomAI();
                break;
            }


            // - - - choose your cpu - - - //
            //create the game
            Game game = new Game(gameai);


            //player inputs: play again, see history, exit
            //TODO: PULL OUT INTO FUNCTION
            //get input
            //loop until quit
            while (true)
            {
                input = "p";
                while (!validateAiInput(input, PlayerActions))
                {
                    Console.WriteLine("Choose what to do");
                    Console.WriteLine("q - quit the game.");
                    Console.WriteLine("h - view history");
                    Console.WriteLine("p - play again");
                    input = Console.ReadLine();
                    input = input.Trim().ToLower();
                }

                switch (input)
                {
                case ("q"):
                    return;

                    break;

                case ("h"):
                    //TODO: print history
                    break;

                case ("p"):
                    //todo: get player input, make match, add to history
                    //maybe delegate to a function in game
                    //COULD EVEN make an interface that handles ai and player moves. Ai inherits from it, player is own class
                    //reads lines from console like we expect here.

                    break;
                }
            }
        }
Exemple #6
0
 private void button4_Click(object sender, EventArgs e)
 {
     if(!on_game)
     {
         return;
     }
     Info.GameState st = Info.GameState.VALID_MOVE;
     AI randomai = new RandomAI();
     while(st != Info.GameState.END_GAME)
     {
         st = board.play(randomai.play(board));
         Refresh();
     }
     double black_point = board.stones[0].size();
     double white_point = board.stones[1].size() + 6.5;
     String msg = "Black " + black_point + " White " + white_point;
     MessageBox.Show(msg);
     on_game = false;
 }
Exemple #7
0
 public Human(Human human, Board board) : base(human, board)
 {
     _randomAi = (RandomAI)human._randomAi.Clone(board);
 }
Exemple #8
0
 public Human(Human human) : base(human)
 {
     _randomAi = (RandomAI)human._randomAi.Clone(Board);
 }
Exemple #9
0
 public Human(Board board, Color color) : base(board, color, "Human " + color)
 {
     _randomAi = new RandomAI(board, color);
 }