コード例 #1
0
        public IActionResult AIMove()
        {
            var model = InitializeModel(ObtainHuPlayer().Name + "'s move", ObtainLogic().Think());

            model = UpdateMoveInfo(model);
            if (model.Logic.IsGameWinnable(pl) == 0)
            {
                PushModel(model);
                return(View("GamePl1", model));
            }
            if (model.Logic.IsGameWinnable(pl) == -1 || model.Logic.IsGameWinnable(en) == -1)
            {
                IScoreService service = ObtainSService();



                service.AddScore(new Score
                {
                    Player = model.Logic.secondPlayer.Name,
                    Points = model.Logic.secondPlayer.GetScore(model.Logic.GameBoard, CellTypes.Player2, model.Logic.boardSize),
                    Time   = DateTime.Now
                });
                service.AddScore(new Score
                {
                    Player = model.Logic.humanPlayer.Name,
                    Points = model.Logic.humanPlayer.GetScore(model.Logic.GameBoard, CellTypes.Player1, model.Logic.boardSize),
                    Time   = DateTime.Now
                });


                return(Content("THE END"));
            }
            model.Logic.secondPlayer = new AIPlayer((Behaviour.Mode)HttpContext.Session.GetObject("ai"), ObtainLogic(), ObtainAIColor());

            Cell[,] g = model.Logic.GameBoard;

            model.Logic.secondPlayer.MakeTurn(ref g);

            model.Logic.GameBoard = g;

            model.Logic.ChangeCellType(CellTypes.Usable, CellTypes.Free);
            model.Logic.Magic(en, pl);
            model.Logic.ChangeCellType(CellTypes.Selected, CellTypes.Player2);
            model.Logic.DetermineUsableCells(en, pl);

            PushModel(model);
            return(View("GamePl1", model));
        }
コード例 #2
0
        public void TestClearScores()
        {
            service.AddScore(new Score {
                Name = "Janko", Points = 120
            });
            service.AddScore(new Score {
                Name = "Katka", Points = 100
            });

            service.ClearScores();

            Assert.AreEqual <int>(0, service.GetTopScores().Count);
        }
コード例 #3
0
        public void AddScorePerformanceTest()
        {
            Stopwatch s = new Stopwatch();

            s.Start();

            _scoreService.AddScore("test2", "test3", Models.Weapons.Weapon.Ak47, Models.BodyParts.BodyPart.Arm).Wait();

            s.Stop();
            Console.WriteLine(s.ElapsedMilliseconds);

            Assert.IsTrue(s.ElapsedMilliseconds < 100);
        }
コード例 #4
0
        public IActionResult addUserData([FromForm] string name, [FromForm] string comment, [FromForm] int rating)
        {
            var field = (Field)HttpContext.Session.GetObject("field");

            _scoreService.AddScore(new Score {
                Name = name, Points = field.Score, TimeOfScore = DateTime.Now
            });
            _commentService.AddComment(new Comment {
                Name = name, Message = comment, TimeOFComment = DateTime.Now
            });
            _ratingService.AddRating(new Rating {
                Name = name, Mark = rating, TimeOfRating = DateTime.Now
            });

            return(RedirectToAction("Index", model));
        }
コード例 #5
0
ファイル: ScoresController.cs プロジェクト: decquart/Arcomage
        public IActionResult Create([FromBody] ScoreModel scoreModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest());
                }

                _scoreService.AddScore(scoreModel.UserId, scoreModel.GameId, scoreModel.Value);
                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest(e.ToString()));
            }
        }
コード例 #6
0
        public void Run()
        {
            var name = ReadName();

            field = new Field();
            do
            {
                PrintField();
                ProcessInput();
            } while (field.State != GameState.SOLVED);

            Console.WriteLine("CONGRATS, U SOLVED THIS PUZZLE");
            scoreService.AddScore(new Score {
                Name = name, Points = field.GetScore(), TimeOfScore = DateTime.Now
            });


            CommentAdding(name);
            RatingAdding(name);

            PrintTopScores();
            PrintLastComments();
            PrintLastRatings();
            PrintAverageRating();



            Console.WriteLine("Want to play one more time?(y/n)");
            String line = ReadInput().ToUpper();

            if (line.Equals("Y"))
            {
                Run();
            }
            else
            {
                Environment.Exit(0);
            }
        }
コード例 #7
0
 public void Post([FromBody] Score score)
 {
     scoreService.AddScore(score);
 }
コード例 #8
0
ファイル: GameLogic.cs プロジェクト: csraea/Othello-Reversi
        public sbyte StartGame()
        {
            FillBoard(CellTypes.Free);
            LocatePlayers();
            Player player    = secondPlayer;
            bool   firstTurn = true;

            do
            {
                player = (player == humanPlayer) ? secondPlayer : humanPlayer;

                if (!skippedTurn)
                {
                    if (player == humanPlayer)
                    {
                        DetermineUsableCells(CellTypes.Player1, CellTypes.Player2);
                    }
                    else
                    {
                        DetermineUsableCells(CellTypes.Player2, CellTypes.Player1);
                    }
                }

                skippedTurn = false;

                // UI based on player's turn. (1,3 - optional)
                if (firstTurn && !ratingService.GetLastRatings().Count.Equals(0))
                {
                    ui.PrintRating(ratingService);
                }
                ui.DisplayGame(humanPlayer, secondPlayer, GameBoard, boardSize);
                if (!firstTurn && secondPlayer.Name.Equals("Handsome Jack") && player == secondPlayer)
                {
                    ui.Think();
                }

                sbyte winnable = IsGameWinnable(player == humanPlayer ? CellTypes.Player1 : CellTypes.Player2);
                if (winnable == -1)
                {
                    break;
                }
                if (winnable == 0)
                {
                    goto NEXTPLAYER;
                }

                Cell[,] gameboard = GameBoard;

                if (!player.MakeTurn(ref gameboard))
                {
                    ui.Exit();
                    return(1);
                }

                GameBoard = gameboard;


                ChangeCellType(CellTypes.Usable, CellTypes.Free);

                if (player == humanPlayer)
                {
                    Magic(CellTypes.Player2, CellTypes.Player1);
                }
                else
                {
                    Magic(CellTypes.Player1, CellTypes.Player2);
                }

                firstTurn = false;

                NEXTPLAYER :;

                Console.WriteLine("" + ((AIPlayer)secondPlayer).ai);
            } while (true);

            scoreService.AddScore(new Score
            {
                Player = humanPlayer.Name, Points = humanPlayer.GetScore(GameBoard, CellTypes.Player1, boardSize),
                Time   = DateTime.Now
            });
            scoreService.AddScore(new Score
            {
                Player = secondPlayer.Name, Points = secondPlayer.GetScore(GameBoard, CellTypes.Player2, boardSize),
                Time   = DateTime.Now
            });
            ui.PrintScores(scoreService);

            Console.ReadLine();
            if (commentService.GetLastComments().Any())
            {
                ui.PrintComments(commentService);
            }
            commentService.AddComment(new Comment
            {
                Player = secondPlayer.Name, Text = ui.GetComment(secondPlayer), Time = DateTime.Now
            });
            commentService.AddComment(new Comment
            {
                Player = humanPlayer.Name, Text = ui.GetComment(humanPlayer), Time = DateTime.Now
            });

            ratingService.Rate(new Rating {
                Mark = ui.GetMark(), Player = humanPlayer.Name
            });
            if (ui.Restart() > -1)
            {
                return(StartGame());
            }
            ui.Exit();

            return(0);
        }
コード例 #9
0
        public IActionResult NewMove(int y, int x)
        {
            byte pla = ObtainPlayer();

            var model = pla == 0
                ? InitializeModel(ObtainSePlayer().Name + "'s move", null)
                : InitializeModel(ObtainHuPlayer().Name + "'s move", null);

            bool mp = (bool)HttpContext.Session.GetObject("Real");

            string view = mp ? "GamePl2" : "GamePl1";

            model = UpdateMoveInfo(model);
            if (model.Logic.IsGameWinnable(pl) == 0)
            {
                PushModel(model);
                return(View(view, model));
            }
            if (model.Logic.IsGameWinnable(pl) == -1 || model.Logic.IsGameWinnable(en) == -1)
            {
                IScoreService service = ObtainSService();



                service.AddScore(new Score
                {
                    Player = model.Logic.secondPlayer.Name,
                    Points = model.Logic.secondPlayer.GetScore(model.Logic.GameBoard, CellTypes.Player2, model.Logic.boardSize),
                    Time   = DateTime.Now
                });
                service.AddScore(new Score
                {
                    Player = model.Logic.humanPlayer.Name,
                    Points = model.Logic.humanPlayer.GetScore(model.Logic.GameBoard, CellTypes.Player1, model.Logic.boardSize),
                    Time   = DateTime.Now
                });



                return(Content("THE END"));
            }
            if (model.Logic.GameBoard[y, x].Type == CellTypes.Usable)
            {
                model.Logic.GameBoard[y, x].Type = CellTypes.Selected;
            }


            else
            {
                model.Message    = "Wrong cell selected!";
                model.NowPlaying = model.NowPlaying == 0 ? (byte)1 : (byte)0;
                PushModel(model);
                return(View(view, model));
            }


            model.Logic.ChangeCellType(CellTypes.Usable, CellTypes.Free);
            model.Logic.Magic(en, pl);
            model.Logic.DetermineUsableCells(en, pl);

            PushModel(model);
            return(View(view, model));
        }