/// <summary> /// Checks if game has ended. If true, OnGameEnded event is invoked. /// </summary> private bool CheckIfGameHasEnded() { GameResult?mateResult = null; if (Bitboard.IsMate(Color.White)) { mateResult = GameResult.BlackWon; } else if (Bitboard.IsMate(Color.Black)) { mateResult = GameResult.WhiteWon; } else if (Bitboard.IsStalemate(Color.White) || Bitboard.IsStalemate(Color.Black) || Bitboard.IsThreefoldRepetition()) { mateResult = GameResult.Draw; } if (mateResult.HasValue) { OnGameEnded?.Invoke(this, new GameEndedEventArgs(mateResult.Value)); return(true); } return(false); }
public void AddStone(BoardIndex index) { if (CellStatus.Available != this[index]) { throw new ArgumentException($"石を配置できない場所です。"); } this.Board.PutStone(new StoneMove(index, this.Board.CurrentTurn), false); var connectIndex = Board.GetConnectIndex(); if (null != connectIndex) { Result = Board[connectIndex].Value.ToResult(); } else { if (!Board.ExistsAvailable) { Result = GameResult.Draw; } else { Result = null; } } }
private void ClearData() { tbLogin.Text = String.Empty; tbPassword.Text = String.Empty; Result = null; Time = null; }
public DialogResult ShowDialog(GameResult result, int time) { Time = time; Result = result; ShowResult(); return(ShowDialog()); }
public RoundResult(GameResult?gameResult, Dictionary <Player, int>?scoreDiffs = null, Dictionary <Player, ExhausiveDrawType>?states = null) { this.gameResult = gameResult; this.scoreDiffs = scoreDiffs; this.states = states; }
public GameLogic(Board <GameBoardCell> i_Board, GamePlayers i_Players) { m_GameResult = null; r_Board = i_Board; r_Players = i_Players; r_State = new GameState((uint)i_Players.Length, i_Board.Rows, i_Board.Cols); m_IndicesOfPlayersThatAreStillPlaying = new List <uint>((int)r_Players.Length); for (uint i = 0; i < r_Players.Length; i++) { m_IndicesOfPlayersThatAreStillPlaying.Add(i); } }
public void Reinitialize() { GameResult = null; TotalMoves = 0; TotalScore = 0; Points = 0; HasInvitation = false; IsPlaying = false; Invitation = null; GamePexeso = null; Moving = false; Opponent = null; MoveCounter = 0; }
public void UpdateResultToWin(ChessColor winner) { EnsureNotFinished(); switch (winner) { case ChessColor.White: Result = GameResult.WonByWhite; return; case ChessColor.Black: Result = GameResult.WonByBlack; return; } }
// If only 1 or 0 players are still in game - returns game result. // If its a draw - no players will be left in game // If its a win - Only the winner stays in the game. private GameResult?getGameResultIfOnlyOnePlayerOrLessLeft() { GameResult?gameResult = null; switch (m_IndicesOfPlayersThatAreStillPlaying.Count) { case 0: gameResult = new GameResult(GameResult.eResult.Draw); break; case 1: gameResult = new GameResult(GameResult.eResult.PlayerWon, m_IndicesOfPlayersThatAreStillPlaying[k_FirstAndOnlyItem]); break; default: break; } return(gameResult); }
private void AffectStatesInternal(GameManagerState desiredState) { _whiteTotalStopwatch.Stop(); _blackTotalStopwatch.Stop(); _whiteLastMoveStopwatch.Stop(); _blackLastMoveStopwatch.Stop(); var gameBoard = GetActiveBoard(); _autoDrawType = AutoDrawType.None; switch (gameBoard.State) { case GameState.Checkmate: _result = gameBoard.ActiveSide == GameSide.White ? GameResult.BlackWon : GameResult.WhiteWon; _state = GameManagerState.GameFinished; return; case GameState.Stalemate: _result = GameResult.Draw; _state = GameManagerState.GameFinished; return; default: _result = null; _autoDrawType = gameBoard.GetAutoDrawType(); if (_autoDrawType != AutoDrawType.None) { _result = GameResult.Draw; _state = GameManagerState.GameFinished; return; } break; } _state = desiredState; }
// If game is over returns valid GameResult, otherwise null private GameResult?getGameResultIfGameOver(Point i_Pos) { GameResult?retGameResult = null; uint? loserIndex = null; retGameResult = getGameResultIfOnlyOnePlayerOrLessLeft(); if (!retGameResult.HasValue) { loserIndex = r_State.GetPlayerIfPointInFullLine(i_Pos, m_IndicesOfPlayersThatAreStillPlaying); if (loserIndex.HasValue) { m_IndicesOfPlayersThatAreStillPlaying.Remove(loserIndex.Value); } else if (IsBoardFull()) { m_IndicesOfPlayersThatAreStillPlaying.Clear(); } retGameResult = getGameResultIfOnlyOnePlayerOrLessLeft(); } return(retGameResult); }
private static void Restart(int type, GameResult?gameResult = null, Choice?randomChoice = null) { string restartText = ""; switch (type) { case 2: restartText = "The choice you entered isn't a correct one. Press any key to reset"; break; case 1: restartText = $"Computer chose: {randomChoice}\nIt's a {gameResult}. Please press any key to reset"; break; case 0: restartText = $"Computer chose: {randomChoice}\nYou {gameResult}. Please press any key to reset"; break; } Console.WriteLine(restartText); Console.ReadKey(); Console.Clear(); RpsGame(); }
public async Task <ActionResult> Index(GameResult?gameResult, string OppTeamName, string gameTime, int dataSort = -1) { List <Game> games; if (gameResult != null && dataSort != null) { games = await GameService.sharedInstance().SortGames((int)dataSort, gameResult); } else { games = await GameService.sharedInstance().getGames(); } games = await GameService.sharedInstance().GameAgainstTeam(OppTeamName, games); games = await GameService.sharedInstance().GetGameByTime(gameTime, games); ViewBag.teams = await TeamService.sharedInstance().getTeams(); ViewBag.results = new List <GameResult> { GameResult.Victory, GameResult.Draw, GameResult.Defeat, GameResult.NC }; return(View(games)); }
// Check and update if a game is over private void updateIsGameOver(Point i_Pos) { m_GameResult = getGameResultIfGameOver(i_Pos); }
public void HandlePlayerQuit(uint i_PlayerIndex) { m_IndicesOfPlayersThatAreStillPlaying.Remove(i_PlayerIndex); m_GameResult = getGameResultIfOnlyOnePlayerOrLessLeft(); }
public void UpdateResultToDraw() { EnsureNotFinished(); Result = GameResult.Draw; }