Exemple #1
0
        /// <summary>
        /// Method for initialize board.
        /// </summary>
        /// <param name="boardSize">Board size</param>
        /// <param name="players">Players list</param>
        /// <returns>Initialized board.</returns>
        public List <Chip> InitBoard(int boardSize, List <IPlayer> players, ChipDoStepDTO blackHole)
        {
            Board = new Board(boardSize, new Chip(blackHole, -1));
            Board.FillBoardInitialValues(players);

            return(Board.OccupiedChips);
        }
Exemple #2
0
 public IActionResult DoStep(int playerId, ChipDoStepDTO chipDoStepDTO)
 {
     try
     {
         return(StatusCode(200, new
         {
             changedChips = PlayerService.DoStep(playerId, chipDoStepDTO),
             nextStepPlayerId = PlayerService.NextStepPlayerId,
             winnerIds = BoardService.Board.WinnerPlayerIdList
         }));
     }
     catch (Exception ex)
     {
         return(StatusCode(400, ex.Message));
     }
 }
Exemple #3
0
        private static void InitClient()
        {
            Initializer initializer = new Initializer();

            colorParser = new ColorParser();
            chipParser  = new ChipParser();

            string        blackHole     = Console.ReadLine();
            ChipDoStepDTO chipBlackHole = chipParser.ParseStringToChip(blackHole);

            string currentPlayerColor = Console.ReadLine();

            boardService  = initializer.InitBoardService();
            playerService = initializer.InitPlayers(colorParser.ParseStringToPlayerColor(currentPlayerColor),
                                                    boardService, out CurrentPlayerId, out OpponentPlayerId);
            initializer.InitBoard(chipBlackHole, playerService, boardService);
        }
Exemple #4
0
        /// <summary>
        /// Method for the player do step.
        /// </summary>
        /// <param name="playerId">Player that do step.</param>
        /// <param name="chipDoStepDTO">The chip that done step.</param>
        /// <returns>Changed chips list.</returns>
        public List <Chip> DoStep(int playerId, ChipDoStepDTO chipDoStepDTO)
        {
            if (!BoardService.CheckInitBoard())
            {
                throw new Exception("Board is not initialized.");
            }
            if (Players == null)
            {
                throw new Exception("Players is not initialized.");
            }

            if (!CheckNextStepPlayerId(playerId))
            {
                throw new Exception("This player is not in the step queue.");
            }

            IPlayer player = Players.Where(player => player.Id == playerId)
                             .FirstOrDefault();

            List <Chip> availableChips = BoardService.GetAvailableSteps(player.Id);
            List <Chip> flippedChips   = new List <Chip>();

            if (availableChips.Count == 0)
            {
                return(flippedChips);
            }

            Chip chipForStep = player.PlayerType == PlayerType.Human ?
                               new Chip(chipDoStepDTO, player.Id) :
                               availableChips[new Random().Next(0, availableChips.Count)];

            if (player.PlayerType == PlayerType.Human &&
                !availableChips.Contains(chipForStep))
            {
                throw new Exception("This step is unavailable!");
            }

            flippedChips = BoardService.FlipChips(chipForStep, player.Id);
            SetNextStepPlayerId(playerId);

            return(flippedChips);
        }
Exemple #5
0
 public void InitBoard(ChipDoStepDTO chipBlackHole,
                       PlayerService playerService, BoardService boardService)
 {
     boardService.InitBoard(8, playerService.Players, chipBlackHole);
 }
Exemple #6
0
 public Chip(ChipDoStepDTO chipDoStepDTO, int playerId)
 {
     this.OwnerId = playerId;
     this.PosX    = chipDoStepDTO.PosX;
     this.PosY    = chipDoStepDTO.PosY;
 }