Example #1
0
        public IActionResult Move(int x, int y)
        {
            var field = HttpContext.Session.GetObject("field") as Field;
            var s     = (int)HttpContext.Session.GetObject("s");

            // int.TryParse(ob, out s);
            var model = new ReversiModel

            {
                Field = field, Scores = scoreService.GetTopScores(), s = s
            };


            if (field.chekUp(model.s, x, y) || field.chekDown(model.s, x, y) || field.chekLeft(model.s, x, y) || field.chekRight(model.s, x, y) ||
                field.chekLU(model.s, x, y) || field.chekLD(model.s, x, y) || field.chekRU(model.s, x, y) || field.chekRD(model.s, x, y))
            {
                field.chekAndRevers(model.s, x, y);

                s++;

                HttpContext.Session.SetObject("field", field);
                HttpContext.Session.SetObject("s", s);
                //return View("Index", model);
            }
            else
            {
                HttpContext.Session.SetObject("field", field);
                return(View("Index", model));
            }


            //HttpContext.Session.SetObject("field", field);

            return(View("Index", model));
        }
Example #2
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);
            }
        }
Example #3
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);
            }
        }
Example #4
0
        public Generator(ReversiModel currentModel)
        {
            model = currentModel;
            rand  = new Random();

            model.SetChips   += (s, ea) => { SetNewChips(s, ea); };
            model.SwitchMove += OnSwitchMove;
            model.GameOver   += OnGameOver;
        }
Example #5
0
        private Color?currentColor; //Current color of this player

        public RandomUser(ReversiModel reversiModel)
        {
            rand = new Random();

            currentColor = null;

            model             = reversiModel;
            model.SwitchMove += OnSwitchMove;
        }
Example #6
0
        public IActionResult Index()
        {
            var field = new Field();

            // field.genrerFled();

            HttpContext.Session.SetObject("field", field);
            HttpContext.Session.SetObject("s", 0);

            var model = new ReversiModel
            {
                s = 0, Field = field, Scores = scoreService.GetTopScores()
            };

            return(View(model));
        }
Example #7
0
        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);
            }
        }
Example #8
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);
            }
        }
Example #9
0
 void Awake()
 {
     reversiModel = new ReversiModel();
     robotPlayer  = new RandomUser(reversiModel);
 }
Example #10
0
 void Start()
 {
     model = holder.reversiModel;
     SubscribeOnEvents();
 }
Example #11
0
 void Start()
 {
     model = holder.reversiModel;
     robot = holder.robotPlayer;
 }