コード例 #1
0
        //Test robot mode (black)
        static void Test2()
        {
            ReversiModel model = new ReversiModel();
            RandomUser   robot = new RandomUser(model);

            model.SwitchMove += (s, ea) => { Console.WriteLine("Switch move {0}", ea.CurrentPlayerColor); };
            model.SwitchMove += (s, ea) =>
            {
                Console.WriteLine(ea.AllowedCells.Count);
                foreach (Cell cell in ea.AllowedCells)
                {
                    Console.WriteLine("{0} {1}", cell.X, cell.Y);
                }
            };

            robot.Enable(Color.White);

            model.NewGame();

            while (true)
            {
                int x = int.Parse(Console.ReadLine());
                int y = int.Parse(Console.ReadLine());
                model.PutChip(x, y);
            }
        }
コード例 #2
0
        //Simulates human to human game mode
        static void Test1()
        {
            ReversiModel model = new ReversiModel();

            model.WrongMove += (s, ea) =>
            {
                Console.WriteLine("Wrong move");
            };
            model.SwitchMove += (s, ea) => { Console.WriteLine("Switch move {0}", ea.CurrentPlayerColor); };
            model.SwitchMove += (s, ea) =>
            {
                foreach (Cell cell in ea.AllowedCells)
                {
                    Console.WriteLine("{0} {1}", cell.X, cell.Y);
                }
            };
            model.CountChanged += (s, ea) => { Console.WriteLine("count {0} {1}", ea.CountBlack, ea.CountWhite); };

            model.NewGame();

            while (true)
            {
                int x = int.Parse(Console.ReadLine());
                int y = int.Parse(Console.ReadLine());
                model.PutChip(x, y);
            }
        }
コード例 #3
0
ファイル: HumanController.cs プロジェクト: Pyrohova/Reversi
    //convert coordinates and put chip
    private void PutChip(string cellName)
    {
        int x = Int32.Parse(cellName[0].ToString());
        int y = Int32.Parse(cellName[1].ToString());

        model.PutChip(x, y);
    }
コード例 #4
0
ファイル: RandomUser.cs プロジェクト: Pyrohova/Reversi
        /*
         * Method that makes random move into one of allowed cells
         * -----------------------------------------
         * allowedCells - cells where user currently can put chip into
         */
        private void MakeMove(SortedSet <Cell> allowedCells)
        {
            int randAllowedCellNumber = rand.Next(allowedCells.Count);

            Cell currentMoveCell = allowedCells.ToList()[randAllowedCellNumber];

            model.PutChip(currentMoveCell.X, currentMoveCell.Y);
        }
コード例 #5
0
        /*
         * Makes next move if it is possible
         */
        public void MakeMove()
        {
            GameIsOver = false;

            Cell moveCell = GetCellToMakeMove();

            if (GameIsOver)
            {
                return;
            }
            model.PutChip(moveCell.X, moveCell.Y);
            Console.WriteLine("{0}{1}", (char)('A' + moveCell.Y), (char)('1' + moveCell.X));
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: Pyrohova/Reversi
        static void Main()
        {
            model          = new ReversiModel();
            generator      = new Generator(model);
            opponentPassed = false;
            Color opponentColor;

            try
            {
                AIGenerator.Cell blackHole = ReadCell();
                playerColor   = ReadColor();
                opponentColor = playerColor == Color.Black ? Color.White : Color.Black;
                generator.StartGame(blackHole, playerColor);

                if (playerColor == Color.Black)
                {
                    generator.MakeMove();
                }

                while (!generator.GameIsOver || !opponentPassed)
                {
                    opponentPassed = false;

                    AIGenerator.Cell opponentMoveCell = ReadOpponentMove();

                    if (!opponentPassed)
                    {
                        model.PutChip(opponentMoveCell.X, opponentMoveCell.Y);
                    }
                    else
                    {
                        model.Pass(opponentColor);
                    }

                    generator.MakeMove();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #7
0
        //Test robot mode (playing for color you want)
        static void Test3(Color userColor)
        {
            ReversiModel model = new ReversiModel();
            RandomUser   robot = new RandomUser(model);

            model.NewGameStarted += (s, ea) => { Console.WriteLine("Game started."); };
            model.SwitchMove     += (s, ea) => { Console.WriteLine("Switch move {0}", ea.CurrentPlayerColor); };
            model.SwitchMove     += (s, ea) =>
            {
                Console.WriteLine(ea.AllowedCells.Count);
                foreach (Cell cell in ea.AllowedCells)
                {
                    Console.WriteLine("{0} {1}", cell.X, cell.Y);
                }
            };

            Color robotColor;

            if (userColor == Color.Black)
            {
                robotColor = Color.White;
            }
            else
            {
                robotColor = Color.Black;
            }

            robot.Enable(robotColor);

            model.NewGame();

            while (true)
            {
                int x = int.Parse(Console.ReadLine());
                int y = int.Parse(Console.ReadLine());
                model.PutChip(x, y);
            }
        }