public void MakeMove(Tuple <int, int> coords) { if (GetAvailableCells().Count == 0) { ChangedTurn(); if (IsGameFinished()) { FinishGame(GetCells()); } } else { PassedMovesCount = 0; } var cells = MarkCell(CurrentPlayerColor, coords, _board.Cells); MoveMade?.Invoke(cells); SwitchPlayer(); AvailableCellsCalculated?.Invoke(GetAvailableCells()); CalculatePlayersScore(cells); if (IsFull(cells) || PassedMovesCount == 2) { FinishGame(cells); return; } _board = new Board(cells); }
private void OnPuzzleButtonClick(object sender, RoutedEventArgs e) { var b = e.Source as Button; if (b != null) { var row = (int)b.GetValue(RowProperty); var col = (int)b.GetValue(ColumnProperty); var moveStatus = _puzzleLogic.GetMoveStatus(row, col); MoveMade?.Invoke(this, new HandledEventArgs(moveStatus != MoveStatus.BadMove)); if (moveStatus != MoveStatus.BadMove) { if (!IsApplyingStyle || !ShouldAnimateInteractions) { // Not templated, just move piece MovePiece(b, row, col); } else { AnimatePiece(b, row, col, moveStatus); } } } }
public void SelectMove(IPlayer player, Move move) { if (CurrentPlayer == player && !m_Game.IsFinished) { CurrentPlayer.MoveProduced -= SelectMove; m_Game.ApplyMove(move); MoveMade?.Invoke(); CurrentPlayer.MoveProduced += SelectMove; CurrentPlayer.TakeTurn(); } }
public void MakeMove(Tuple <int, int> coolds) { passedMovesCount = 0; field.SetCell(currentPlayerColor, coolds); MoveMade?.Invoke(field.Cells); SwitchPlayer(); if (field.isFull() || passedMovesCount == 2) { FinishGame(); return; } }
public void MakeMove(Tuple <int, int> coolds) { if (GetAvailablePoints().Count == 0) { Pass(); } else { passedMovesCount = 0; } List <List <Point> > points = BoardHandler.SetPoint(currentPlayerColor, coolds, board.Points); MoveMade?.Invoke(points); SwapTurn(); AvailablePointsCalculated?.Invoke(GetAvailablePoints()); CalculatePlayersScore(points); if (BoardHandler.isFull(points) || passedMovesCount == 2) { FinishGame(points); return; } board = new Board(points); }
private void OnMove(int gridX, int gridY, int X, int Y) { MoveMade?.Invoke(this, new TicTacToeTurnEventArgs(WhoseTurn, NextMoveX, NextMoveY, gridX, gridY, X, Y)); }
/// <summary> /// Raises the <see cref="MoveMade"/> event. /// </summary> protected virtual void OnMoveMade(CubeMove move) { MoveMade?.Invoke(this, move); }
public GameResult PlayGame(ChessGame startingPosition = null) { var game = startingPosition ?? new ChessGame(); var gameResult = new GameResult(); GameStats.GameCount += 1; while (game.WhoseTurn != Player.None) { if (game.DrawCanBeClaimed) { gameResult.Result = "Draw"; game.ClaimDraw("Boredom"); GameStats.DrawCount += 1; break; } var move = (game.WhoseTurn == Player.White ? WhiteAgent : BlackAgent).GenerateMove(game); GameStats.MoveCount += 1; gameResult.MoveCount += 1; var gameBeforeMove = new ChessGame(game.GetGameCreationData()); game.MakeMove(move, true); var gameAfterMove = new ChessGame(game.GetGameCreationData()); // raise event MoveMade?.Invoke(gameBeforeMove, move, gameAfterMove); if (game.IsInCheck(game.WhoseTurn)) { GameStats.CheckCount += 1; gameResult.CheckCount += 1; } if (game.IsStalemated(game.WhoseTurn)) { GameStats.StalemateCount += 1; gameResult.Result = "Stalemate"; break; } if (game.IsCheckmated(game.WhoseTurn)) { gameResult.Result = "Checkmate"; gameResult.Winner = game.WhoseTurn == Player.White ? Player.Black : Player.White; if (gameResult.Winner == Player.White) { GameStats.WhiteCheckmateCount += 1; } else { GameStats.BlackCheckmateCount += 1; } break; } } // raise event GameConcluded?.Invoke(new ChessGame(game.GetGameCreationData()), gameResult); return(gameResult); }