enemy goes fiorst
This commit is contained in:
parent
3c72b5e6d0
commit
8125d13e57
5 changed files with 34 additions and 21 deletions
|
|
@ -157,7 +157,7 @@ func _on_new_game_requested(options = {}):
|
||||||
cardDisplay.visible = true
|
cardDisplay.visible = true
|
||||||
if stateMachine:
|
if stateMachine:
|
||||||
stateMachine.enable()
|
stateMachine.enable()
|
||||||
stateMachine.transitionToNextState(Constants.WHITE_TURN)
|
stateMachine.transitionToNextState(Constants.BLACK_TURN)
|
||||||
else:
|
else:
|
||||||
initialize_game_system(mode == "vanilla")
|
initialize_game_system(mode == "vanilla")
|
||||||
if currentFen:
|
if currentFen:
|
||||||
|
|
@ -187,7 +187,7 @@ func initialize_game_system(skip_preload: bool = false):
|
||||||
# Start the state machine
|
# Start the state machine
|
||||||
if stateMachine:
|
if stateMachine:
|
||||||
stateMachine.start()
|
stateMachine.start()
|
||||||
stateMachine.transitionToNextState(Constants.WHITE_TURN)
|
stateMachine.transitionToNextState(Constants.BLACK_TURN)
|
||||||
|
|
||||||
# Mark as initialized
|
# Mark as initialized
|
||||||
is_initialized = true
|
is_initialized = true
|
||||||
|
|
|
||||||
|
|
@ -43,12 +43,18 @@ func initialize(options = null):
|
||||||
player = game.player
|
player = game.player
|
||||||
update_display()
|
update_display()
|
||||||
|
|
||||||
|
if deeper_button:
|
||||||
|
deeper_button.disabled = player.get_run_count() == 0
|
||||||
|
|
||||||
func update_display():
|
func update_display():
|
||||||
if player:
|
if player:
|
||||||
if run_count_label:
|
if run_count_label:
|
||||||
run_count_label.text = "RUN #" + str(player.get_run_count() + 1)
|
run_count_label.text = "RUN #" + str(player.get_run_count() + 1)
|
||||||
|
|
||||||
|
|
||||||
|
if deeper_button:
|
||||||
|
deeper_button.disabled = player.run_count == 0
|
||||||
|
|
||||||
if token_label:
|
if token_label:
|
||||||
token_label.text = str(player.tokens) + " TOKENS"
|
token_label.text = str(player.tokens) + " TOKENS"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,7 @@ func _on_turn_changed():
|
||||||
|
|
||||||
func on_piece_captured(piece):
|
func on_piece_captured(piece):
|
||||||
# print("on_piece_captured ISEnemy ", 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)
|
print("on_piece_captured ISEnemy ", is_enemy_piece)
|
||||||
if is_enemy_piece:
|
if is_enemy_piece:
|
||||||
captured_pieces.append(piece)
|
captured_pieces.append(piece)
|
||||||
|
|
@ -140,7 +140,7 @@ func on_piece_captured(piece):
|
||||||
check_conditions()
|
check_conditions()
|
||||||
|
|
||||||
func on_piece_lost(piece):
|
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)
|
print("on_piece_lost isPlayer ", is_player_piece)
|
||||||
|
|
||||||
if 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):
|
func on_piece_moved(piece, from_location, to_location):
|
||||||
if win_condition == Utils.WinConditionType.TILE_REACHED:
|
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 is_player_piece and target_tiles.has(to_location):
|
||||||
if "unit" in win_condition_data and win_condition_data["unit"] != "":
|
if "unit" in win_condition_data and win_condition_data["unit"] != "":
|
||||||
|
|
@ -208,7 +208,7 @@ func check_conditions():
|
||||||
func count_enemy_pieces() -> int:
|
func count_enemy_pieces() -> int:
|
||||||
var count = 0
|
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 y in range(chess_game.boardYSize):
|
||||||
for x in range(chess_game.boardXSize):
|
for x in range(chess_game.boardXSize):
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ func check_win_conditions() -> bool:
|
||||||
var target_unit = game.winConditionManager.win_condition_data.get("unit", "King")
|
var target_unit = game.winConditionManager.win_condition_data.get("unit", "King")
|
||||||
|
|
||||||
for piece in game.captured_pieces_this_turn:
|
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!
|
# Found captured target piece - win condition met!
|
||||||
var condition_data = {
|
var condition_data = {
|
||||||
"type": Utils.WinConditionType.CAPTURE_UNIT,
|
"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")
|
var target_unit = game.winConditionManager.loss_condition_data.get("unit", "King")
|
||||||
|
|
||||||
for piece in game.player_pieces_lost_this_turn:
|
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!
|
# Found lost target piece - loss condition met!
|
||||||
var condition_data = {
|
var condition_data = {
|
||||||
"type": Utils.LossConditionType.UNIT_LOST,
|
"type": Utils.LossConditionType.UNIT_LOST,
|
||||||
|
|
@ -113,3 +113,9 @@ func check_loss_conditions() -> bool:
|
||||||
return true
|
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))
|
||||||
|
|
@ -71,15 +71,13 @@ func exit() -> void:
|
||||||
game.boardContainer.disconnect("tile_pressed", handleMovement)
|
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:
|
func handleMovement(location: String, generated: bool = false) -> void:
|
||||||
# we need to prevent swapping of focus between peices after the double move process has started
|
# 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
|
# maybe once u start nmoving a peice global stat var is set
|
||||||
# and any moving peice needs ot match that
|
# and any moving peice needs ot match that
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var node = game.get_node("Flow/" + location) as PieceContainer
|
var node = game.get_node("Flow/" + location) as PieceContainer
|
||||||
print("HANDLING MOVEMENT ", location, " | ", last_selected, " | ", game.selectedNode)
|
print("HANDLING MOVEMENT ", location, " | ", last_selected, " | ", game.selectedNode)
|
||||||
if node.has_piece():
|
if node.has_piece():
|
||||||
|
|
@ -103,7 +101,8 @@ func handleMovement(location: String, generated: bool = false) -> void:
|
||||||
# print("No Node")
|
# print("No Node")
|
||||||
# If no node is selected, we might want to select this one if it has a piece
|
# If no node is selected, we might want to select this one if it has a piece
|
||||||
var piece = node.get_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.selectedNode = location
|
||||||
game.getMovableAreas()
|
game.getMovableAreas()
|
||||||
last_selected = location
|
last_selected = location
|
||||||
|
|
@ -156,12 +155,12 @@ func handleMovement(location: String, generated: bool = false) -> void:
|
||||||
var attempting_piece = node.get_piece()
|
var attempting_piece = node.get_piece()
|
||||||
# print("Checking Str comp ", str(attempting_piece.get_instance_id()), " ", multiMoving)
|
# print("Checking Str comp ", str(attempting_piece.get_instance_id()), " ", multiMoving)
|
||||||
# Only block if it's a different piece of the same color
|
# 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")
|
print("early return - can't select different piece of same color during multi-move")
|
||||||
return
|
return
|
||||||
if game.selectedNode == "":
|
if game.selectedNode == "":
|
||||||
# print("No Node 2")
|
# 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)
|
# print("SELECTED NODE ", location)
|
||||||
game.selectedNode = location
|
game.selectedNode = location
|
||||||
game.getMovableAreas()
|
game.getMovableAreas()
|
||||||
|
|
@ -246,18 +245,20 @@ func handleMovement(location: String, generated: bool = false) -> void:
|
||||||
|
|
||||||
|
|
||||||
func isCastlingMove(node: PieceContainer, location: String) -> bool:
|
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:
|
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().name == "Pawn" && game.specialArea.size() != 0 && game.specialArea[0] == node.name && \
|
||||||
node.get_piece().get("En_Passant") == true
|
node.get_piece().get("En_Passant") == true
|
||||||
|
|
||||||
func isReselectMove(node: PieceContainer) -> bool:
|
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:
|
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:
|
func isRegularMove(node: PieceContainer) -> bool:
|
||||||
return game.selectedNode != "" && node.get_piece() != null
|
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
|
# Handle capture if there's a piece in the target location
|
||||||
if targetContainer.has_piece():
|
if targetContainer.has_piece():
|
||||||
var capturedPiece = targetContainer.get_piece()
|
var capturedPiece = targetContainer.get_piece()
|
||||||
if game.Turn == 0:
|
if game.currentPlayer == game.WHITE:
|
||||||
game.p1Points += capturedPiece.Points
|
game.p1Points += capturedPiece.Points
|
||||||
game.p1String.text = str(game.p1Points)
|
game.p1String.text = str(game.p1Points)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue