42 lines
1.5 KiB
GDScript
42 lines
1.5 KiB
GDScript
extends "res://Systems/StateMachine/ChessGameState.gd"
|
|
|
|
|
|
var moveTimer: Timer
|
|
var stateDelay: Timer
|
|
|
|
func _ready() -> void:
|
|
moveTimer = Timer.new()
|
|
moveTimer.one_shot = true # Timer only fires once
|
|
moveTimer.connect("timeout", _on_move_timer_timeout)
|
|
add_child(moveTimer)
|
|
stateDelay = Timer.new()
|
|
stateDelay.one_shot = true # Timer only fires once
|
|
stateDelay.connect("timeout", _on_state_delay_timeout)
|
|
add_child(stateDelay)
|
|
|
|
func enter(_previous: String, _data := {}) -> void:
|
|
print("ENTERING STATE ", Constants.BLACK_TURN)
|
|
game.currentPlayer = game.BLACK
|
|
game.updateTurnIndicator()
|
|
var variant = game.get_board_dimensions(game.currentFen)
|
|
game.stockfishController.setVariant(variant)
|
|
game.stockfishController.clear_game()
|
|
# Delay to avoid duplication during animation
|
|
if game.stockfishController:
|
|
moveTimer.start(2)
|
|
|
|
func _on_move_timer_timeout() -> void:
|
|
# Generate AI move after delay
|
|
print("------------------GENERATING MOVE --------------------")
|
|
if game.stockfishController:
|
|
print("------------------STARTING GENERATING MOVE --------------------")
|
|
|
|
game.stockfishController.load_fen(game.generate_variant_aware_fen())
|
|
OS.delay_msec(250)
|
|
game.stockfishController.generateMove(1000) # 1 second think time
|
|
stateDelay.start(2)
|
|
|
|
func _on_state_delay_timeout() -> void:
|
|
finished.emit(Constants.HAND_SETUP)
|
|
func exit() -> void:
|
|
moveTimer.stop()
|