enemy goes fiorst

This commit is contained in:
2ManyProjects 2025-03-16 11:15:09 -05:00
parent 3c72b5e6d0
commit 8125d13e57
5 changed files with 34 additions and 21 deletions

View file

@ -157,7 +157,7 @@ func _on_new_game_requested(options = {}):
cardDisplay.visible = true
if stateMachine:
stateMachine.enable()
stateMachine.transitionToNextState(Constants.WHITE_TURN)
stateMachine.transitionToNextState(Constants.BLACK_TURN)
else:
initialize_game_system(mode == "vanilla")
if currentFen:
@ -187,7 +187,7 @@ func initialize_game_system(skip_preload: bool = false):
# Start the state machine
if stateMachine:
stateMachine.start()
stateMachine.transitionToNextState(Constants.WHITE_TURN)
stateMachine.transitionToNextState(Constants.BLACK_TURN)
# Mark as initialized
is_initialized = true

View file

@ -42,6 +42,9 @@ func initialize(options = null):
if game and "player" in game:
player = game.player
update_display()
if deeper_button:
deeper_button.disabled = player.get_run_count() == 0
func update_display():
if player:
@ -49,6 +52,9 @@ func update_display():
run_count_label.text = "RUN #" + str(player.get_run_count() + 1)
if deeper_button:
deeper_button.disabled = player.run_count == 0
if token_label:
token_label.text = str(player.tokens) + " TOKENS"

View file

@ -114,7 +114,7 @@ func _on_turn_changed():
func on_piece_captured(piece):
# print("on_piece_captured ISEnemy ", piece)
var is_enemy_piece = piece.Item_Color == (1 if chess_game.Turn == 1 else 0)
var is_enemy_piece = piece.Item_Color == (1 if chess_game.currentPlayer == chess_game.BLACK else 0)
print("on_piece_captured ISEnemy ", is_enemy_piece)
if is_enemy_piece:
captured_pieces.append(piece)
@ -140,7 +140,7 @@ func on_piece_captured(piece):
check_conditions()
func on_piece_lost(piece):
var is_player_piece = piece.Item_Color == (0 if chess_game.Turn == 1 else 1)
var is_player_piece = piece.Item_Color == (0 if chess_game.currentPlayer == chess_game.BLACK else 1)
print("on_piece_lost isPlayer ", is_player_piece)
if is_player_piece:
@ -156,7 +156,7 @@ func on_piece_lost(piece):
func on_piece_moved(piece, from_location, to_location):
if win_condition == Utils.WinConditionType.TILE_REACHED:
var is_player_piece = piece.Item_Color == (0 if chess_game.Turn == 0 else 1)
var is_player_piece = piece.Item_Color == (0 if chess_game.currentPlayer == chess_game.WHITE else 1)
if is_player_piece and target_tiles.has(to_location):
if "unit" in win_condition_data and win_condition_data["unit"] != "":
@ -208,7 +208,7 @@ func check_conditions():
func count_enemy_pieces() -> int:
var count = 0
var enemy_color = 1 if chess_game.Turn == 0 else 0
var enemy_color = 1 if chess_game.currentPlayer == chess_game.WHITE else 0
for y in range(chess_game.boardYSize):
for x in range(chess_game.boardXSize):

View file

@ -25,7 +25,7 @@ func check_win_conditions() -> bool:
var target_unit = game.winConditionManager.win_condition_data.get("unit", "King")
for piece in game.captured_pieces_this_turn:
if piece.name == target_unit and piece.Item_Color == (1 if game.Turn == 0 else 0):
if piece.name == target_unit and piece.Item_Color == (1 if game.currentPlayer == game.WHITE else 0):
# Found captured target piece - win condition met!
var condition_data = {
"type": Utils.WinConditionType.CAPTURE_UNIT,
@ -91,7 +91,7 @@ func check_loss_conditions() -> bool:
var target_unit = game.winConditionManager.loss_condition_data.get("unit", "King")
for piece in game.player_pieces_lost_this_turn:
if piece.name == target_unit and piece.Item_Color == (0 if game.Turn == 0 else 1):
if piece.name == target_unit and piece.Item_Color == (0 if game.currentPlayer == game.WHITE else 1):
# Found lost target piece - loss condition met!
var condition_data = {
"type": Utils.LossConditionType.UNIT_LOST,
@ -112,4 +112,10 @@ func check_loss_conditions() -> bool:
finished.emit(Constants.CLEANUP, {"endCondition": "turn_limit_exceeded"})
return true
return false
return false
func pieceItemColourTurnMatch(colour): #0 white, 1 black
return ((colour == 0) and (game.currentPlayer == game.WHITE)) || ((colour == 1) and (game.currentPlayer == game.BLACK))

View file

@ -71,15 +71,13 @@ func exit() -> void:
game.boardContainer.disconnect("tile_pressed", handleMovement)
func pieceItemColourTurnMatch(colour): #0 white, 1 black
return ((colour == 0) and (game.currentPlayer == game.WHITE)) || ((colour == 1) and (game.currentPlayer == game.BLACK))
func handleMovement(location: String, generated: bool = false) -> void:
# we need to prevent swapping of focus between peices after the double move process has started
# maybe once u start nmoving a peice global stat var is set
# and any moving peice needs ot match that
var node = game.get_node("Flow/" + location) as PieceContainer
print("HANDLING MOVEMENT ", location, " | ", last_selected, " | ", game.selectedNode)
if node.has_piece():
@ -103,7 +101,8 @@ func handleMovement(location: String, generated: bool = false) -> void:
# print("No Node")
# If no node is selected, we might want to select this one if it has a piece
var piece = node.get_piece()
if piece != null && piece.Item_Color == game.Turn:
if piece != null && pieceItemColourTurnMatch(piece.Item_Color):
game.selectedNode = location
game.getMovableAreas()
last_selected = location
@ -156,12 +155,12 @@ func handleMovement(location: String, generated: bool = false) -> void:
var attempting_piece = node.get_piece()
# print("Checking Str comp ", str(attempting_piece.get_instance_id()), " ", multiMoving)
# Only block if it's a different piece of the same color
if str(attempting_piece.get_instance_id()) != multiMoving and attempting_piece.Item_Color == game.Turn:
if str(attempting_piece.get_instance_id()) != multiMoving and pieceItemColourTurnMatch(attempting_piece.Item_Color):
print("early return - can't select different piece of same color during multi-move")
return
if game.selectedNode == "":
# print("No Node 2")
if node.get_piece() != null && node.get_piece().Item_Color == game.Turn:
if node.get_piece() != null && pieceItemColourTurnMatch(node.get_piece().Item_Color):
# print("SELECTED NODE ", location)
game.selectedNode = location
game.getMovableAreas()
@ -246,18 +245,20 @@ func handleMovement(location: String, generated: bool = false) -> void:
func isCastlingMove(node: PieceContainer, location: String) -> bool:
return game.selectedNode != "" && node.get_piece() != null && node.get_piece().Item_Color == game.Turn && node.get_piece().name == "Rook"
return game.selectedNode != "" && node.get_piece() != null && pieceItemColourTurnMatch(node.get_piece().Item_Color) && node.get_piece().name == "Rook"
func isEnPassantMove(node: PieceContainer, location: String) -> bool:
return game.selectedNode != "" && node.get_piece() != null && node.get_piece().Item_Color != game.Turn && \
return game.selectedNode != "" && node.get_piece() != null && !pieceItemColourTurnMatch(node.get_piece().Item_Color) && \
node.get_piece().name == "Pawn" && game.specialArea.size() != 0 && game.specialArea[0] == node.name && \
node.get_piece().get("En_Passant") == true
func isReselectMove(node: PieceContainer) -> bool:
return game.selectedNode != "" && node.get_piece() != null && node.get_piece().Item_Color == game.Turn
return game.selectedNode != "" && node.get_piece() != null && pieceItemColourTurnMatch(node.get_piece().Item_Color)
func isCaptureMove(node: PieceContainer) -> bool:
return game.selectedNode != "" && node.get_piece() != null && node.get_piece().Item_Color != game.Turn
return game.selectedNode != "" && node.get_piece() != null && !pieceItemColourTurnMatch(node.get_piece().Item_Color)
func isRegularMove(node: PieceContainer) -> bool:
return game.selectedNode != "" && node.get_piece() != null
@ -375,7 +376,7 @@ func executeMove(targetLocation: String) -> void:
# Handle capture if there's a piece in the target location
if targetContainer.has_piece():
var capturedPiece = targetContainer.get_piece()
if game.Turn == 0:
if game.currentPlayer == game.WHITE:
game.p1Points += capturedPiece.Points
game.p1String.text = str(game.p1Points)
else: