Skip to content

Commit

Permalink
[GUI] Automatic turns first take
Browse files Browse the repository at this point in the history
Disabled. Not tested yet.
  • Loading branch information
dodikk committed Dec 19, 2015
1 parent 2d87d7e commit d858145
Showing 1 changed file with 57 additions and 7 deletions.
64 changes: 57 additions & 7 deletions Reversi/Assets/BoardEventsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,14 @@ void Update()
}
#endregion

private void getAvailableTurns()
{
var turns = this._turnCalculator.GetValidTurnsForBoard(this._boardModel);
this._validTurns = turns;
}


#region Human Player Turn
private void handleMouseUpEvent()
{
Vector3 mousePosition = Input.mousePosition;
Expand All @@ -76,6 +83,12 @@ private void handleMouseUpEvent()

private void handleTapOnCell(GameObject cellCube)
{
if (this.IsTurnOfAI)
{
return;
}


// TODO : maybe compute matrix index by reference
string cellName = cellCube.name;

Expand Down Expand Up @@ -112,6 +125,15 @@ private void handleTapOnCell(GameObject cellCube)
}
IReversiTurn turn = turnsSetToMatchInput.First();
this.makeTurn(turn);


if (IS_OPPONENT_PLAYER_AI)
{
while (this.IsTurnOfAI)
{
this.makeTurnByAI();
}
}
}

private void makeTurn(IReversiTurn turn)
Expand All @@ -126,9 +148,42 @@ private void makeTurn(IReversiTurn turn)
{
this._turnLabel.text = "Game Over";
this._isGameOver = true;

return;
}
}
#endregion

private void makeTurnByAI()
{
IReversiTurn selectedTurn =
this._turnSelector.SelectBestTurnOnBoard(
this._validTurns,
this._boardModel);

this.makeTurn(selectedTurn);
}

private bool IsTurnOfAI
{
get
{
if (this._isGameOver)
{
return false;
}

if (!this.IS_OPPONENT_PLAYER_AI)
{
return false;
}

return !this._boardModel.IsTurnOfBlackPlayer;
}
}


#region Turn Drawing
private void drawChangesForTurn(IReversiTurn turn)
{
Material activePlayerColour =
Expand Down Expand Up @@ -183,12 +238,6 @@ private void updateTurnLabel()
"White Player Turn" ;
}

private void getAvailableTurns()
{
var turns = this._turnCalculator.GetValidTurnsForBoard(this._boardModel);
this._validTurns = turns;
}

private void updateBallColours()
{
for (int row = 0; row != BOARD_SIZE; ++row)
Expand All @@ -214,6 +263,7 @@ private void updateScoreLabels()
this._blackScoreLabel.text = "Black : " + Convert.ToString(blackScore);
this._whiteScoreLabel.text = "White : " + Convert.ToString(whiteScore);
}
#endregion

#region Turn Highlight
private void unhighlightAvailableTurns()
Expand Down Expand Up @@ -413,7 +463,7 @@ private void populateLabels()

#endregion

private static bool IS_OPPONENT_PLAYER_AI = false;
private bool IS_OPPONENT_PLAYER_AI = false;

private const int BOARD_SIZE = 8;
private const string CELL_TAG = "FieldCell";
Expand Down

0 comments on commit d858145

Please sign in to comment.