public void Update() { if (CurrentPlayer.HasPassed() && _player2.HasPassed()) { int ScoreFor(PlayerColor color) => _logicalBoard.LogicalState.Count(piece => piece.Color == color); int scoreBlack = ScoreFor(PlayerColor.Black); int scoreWhite = ScoreFor(PlayerColor.White); if (scoreWhite == scoreBlack) { playerText.text = "Draw!"; scoreText.text = scoreBlack + " : " + scoreWhite; } else if (scoreBlack > scoreWhite) { playerText.text = "BLACK wins!"; scoreText.text = scoreBlack + " : " + scoreWhite; } else { playerText.text = "WHITE wins!"; scoreText.text = scoreWhite + " : " + scoreBlack; } canvas.SetActive(true); return; } if (!CurrentPlayer.HasNextMove()) { NextPlayer(true); return; } List <Move> nextMove = CurrentPlayer.GetNextMove(); if (nextMove.Count == 0) { return; } _logicalBoard = _logicalBoard.With(nextMove); NextPlayer(false); }
public void Awake() { BoardLength = PlayerPrefs.GetInt("BoardLength"); if (BoardLength < 6 || BoardLength > 10 || BoardLength % 2 != 0) { BoardLength = 8; } mainCamera.transform.position = GetCameraTransform(); _logicalBoard = new Board.Board(BoardLength); _player1 = GetPlayerFor(PlayerColor.Black); _player2 = GetPlayerFor(PlayerColor.White); CurrentPlayer = _player1; Instance = this; }
private void GeneratePhysicalBoard() { int middle = BoardLength / 2; int offMiddle = middle - 1; void CreateTileAt(int x, int z) => Instantiate(tilePref, new Vector3(x, 0, z), Quaternion.identity) .transform.SetParent(board.transform); for (int x = 0; x < BoardLength; x++) { for (int z = 0; z < BoardLength; z++) { CreateTileAt(x, z); } } _logicalBoard = _logicalBoard .With(new LogicalPiece(offMiddle, offMiddle, PlayerColor.Black)) .With(new LogicalPiece(offMiddle, middle, PlayerColor.White)) .With(new LogicalPiece(middle, middle, PlayerColor.Black)) .With(new LogicalPiece(middle, offMiddle, PlayerColor.White)); }