public bool TryMove(CheckerMove move, bool end) { var success = false; if (_allCheckers.ContainsKey(move.oldCoords)) { var checker = _allCheckers[move.oldCoords]; var isValidMove = checker.IsValidMove(move.destinationCoords); var isValidKill = !move.isKill || _allCheckers.ContainsKey(move.killCoords); success = isValidMove && isValidKill; if (success) { if (move.isKill) { var killedChecker = _allCheckers[move.killCoords]; _allCheckers.Remove(move.killCoords); bool isKilledWhite = killedChecker.IsWhite; if (isKilledWhite) { WhiteCheckers.Remove(killedChecker); } else { BlackCheckers.Remove(killedChecker); } killedChecker.Die(); } Debug.Log("SetCoords"); checker.SetCoords(move.destinationCoords); _allCheckers.Remove(move.oldCoords); _allCheckers.Add(move.destinationCoords, checker); // Check end game. if (WhiteCheckers.Count == 0) { OnGameEnd(false); } else if (BlackCheckers.Count == 0) { OnGameEnd(true); } } } if (success && end) { isWhiteMove = !isWhiteMove; } return(success); }