Fix human player able to make illegal move during bot's turn

This commit is contained in:
Sebastian Lague 2023-07-22 13:18:30 +02:00
parent 3711d23f1e
commit 85219733d3

View file

@ -14,6 +14,7 @@ namespace ChessChallenge.Application
// State
bool isDragging;
int selectedSquare;
bool isTurnToMove;
public HumanPlayer(BoardUI boardUI)
@ -25,7 +26,7 @@ namespace ChessChallenge.Application
public void NotifyTurnToMove()
{
isTurnToMove = true;
}
public void SetPosition(string fen)
@ -35,6 +36,10 @@ namespace ChessChallenge.Application
public void Update()
{
if (!isTurnToMove)
{
return;
}
Vector2 mouseScreenPos = Raylib.GetMousePosition();
Vector2 mouseWorldPos = Program.ScreenToWorldPos(mouseScreenPos);
@ -98,6 +103,7 @@ namespace ChessChallenge.Application
if (isLegal)
{
isTurnToMove = false;
MoveChosen?.Invoke(move);
}
}