private void SelectCell(int x, BLL.DTO.GameState gameState) { var y = (GetLowestFreeCell(x, gameState)); gameState.Board[y, x] = gameState.PlayerOneTurn ? 1 : 2; CheckForWin(gameState); }
private void TurnSwitch(BLL.DTO.GameState gameStateOuter, GameState gameStateInner) { gameStateOuter.PlayerOneTurn = !gameStateOuter.PlayerOneTurn; gameStateInner.Turn = !gameStateInner.Turn; if (CheckIfBoardIsFull(gameStateOuter)) { gameStateOuter.Winner = DTO.GameState.Win.DRAW; } }
private int GetLowestFreeCell(int x, BLL.DTO.GameState gameState) { for (int y = gameState.Height - 1; y >= 0; y--) { if (gameState.Board[y, x] == 0) { return(y); } } return(0); }
private async Task <DTO.GameState> CreateGameState(BLL.DTO.GameState gameState) { FillArray(gameState.Board); if (gameState.GameMode == GameMode.AI_FIRST) { GenerateAIMove(gameState); gameState.PlayerOneTurn = true; } gameState.StateId = await SaveGameState(gameState); return(gameState); }
private DTO.GameState MapFromDb(GameState innerGameState) { var outerGameState = new BLL.DTO.GameState() { StateId = innerGameState.GameStateId, Height = innerGameState.BoardHeight, Width = innerGameState.BoardWidth, Board = DeserializeBoard(innerGameState.BoardJson), GameMode = innerGameState.GameMode, PlayerOneTurn = innerGameState.Turn }; return(outerGameState); }
public async Task <BLL.DTO.GameState> CreateGameStateFromSettings() { var gameSettings = await GetGameSettings(); var gameState = new BLL.DTO.GameState() { Height = gameSettings.BoardHeight, Width = gameSettings.BoardWidth, Board = new int[gameSettings.BoardHeight, gameSettings.BoardWidth], PlayerOneTurn = false, GameMode = gameSettings.GameMode }; return(await CreateGameState(gameState)); }
private void GenerateAIMove(BLL.DTO.GameState gameState) { Random r = new Random(); while (true) { var rInt = r.Next(0, gameState.Width); if (gameState.Board[0, rInt] != 0) { continue; } SelectCell(rInt, gameState); break; } }
public Task <int> SaveGameState(BLL.DTO.GameState gameState) { return(_stateRepository.SaveGameState(MapFromPage(gameState))); }