Zerge Boss support

This commit is contained in:
2ManyProjects 2025-03-09 17:13:04 -05:00
parent 7df56f5855
commit 21688aa11b
10 changed files with 72 additions and 23 deletions

View file

@ -28,7 +28,9 @@ class ChessEngine extends EventEmitter {
this.engine.on('close', (code) => { this.engine.on('close', (code) => {
console.log('Engine process closed with code:', code); console.log('Engine process closed with code:', code);
this.isReady = false; // this.isReady = false;
//Certainly this cant go horrifically wrong
start()
}); });
// Initialize engine // Initialize engine

View file

@ -17,7 +17,7 @@ func reset():
valid = false valid = false
func apply_effect(target_piece = null, board_flow = null, game_state = null): func apply_effect(target_piece = null, board_flow = null, game_state = null):
print("EXPLOSIVE apply_effect", ) print("EXPLOSIVE apply_effect", target_piece)
attached_piece = target_piece attached_piece = target_piece
stored_board_flow = board_flow stored_board_flow = board_flow
stored_game_state = game_state stored_game_state = game_state
@ -111,6 +111,8 @@ func setup_persistent_effect(game_state):
func on_turn_changed(): func on_turn_changed():
print("TURN CHANGED ==================", stored_game_state.isPlayerTurn() ) print("TURN CHANGED ==================", stored_game_state.isPlayerTurn() )
if stored_game_state.stateMachine.disabled:
return
if stored_game_state.isPlayerTurn() and attached_piece and remaining_turns > 0: if stored_game_state.isPlayerTurn() and attached_piece and remaining_turns > 0:
var piece = attached_piece var piece = attached_piece

View file

@ -103,10 +103,12 @@ func _ready() -> void:
turnIndicator.visible = false turnIndicator.visible = false
deckManager = DeckManager.new() deckManager = DeckManager.new()
# 2rnbqkbnr1R/2ppp1pppp2/5p6/75/66/66/66/66/66/66/2PPPPPPPP2/2RNBQKBN3 b KQkq - 0 3 # 2rnbqkbnr1R/2ppp1pppp2/5p6/75/66/66/66/66/66/66/2PPPPPPPP2/2RNBQKBN3 b KQkq - 0 3
# clear prev wind conditions?
func _on_new_game_requested(options = {}): func _on_new_game_requested(options = {}):
print("ChessGame received new_game_requested signal ", is_initialized) print("ChessGame received new_game_requested signal ", is_initialized)
captured_pieces_this_turn = [] captured_pieces_this_turn = []
player_pieces_lost_this_turn = [] player_pieces_lost_this_turn = []
moveCount = 1
turnIndicator.visible = true turnIndicator.visible = true
has_opponent = true has_opponent = true
if cameraController: if cameraController:
@ -137,6 +139,7 @@ func _on_new_game_requested(options = {}):
if cardDisplay: if cardDisplay:
cardDisplay.visible = true cardDisplay.visible = true
if stateMachine: if stateMachine:
stateMachine.enable()
stateMachine.transitionToNextState(Constants.WHITE_TURN) stateMachine.transitionToNextState(Constants.WHITE_TURN)
else: else:
initialize_game_system() initialize_game_system()
@ -796,13 +799,16 @@ func check_captured_pieces_conditions():
if winConditionManager: if winConditionManager:
winConditionManager.on_piece_captured(piece) winConditionManager.on_piece_captured(piece)
print(captured_pieces_this_turn) print(captured_pieces_this_turn)
captured_pieces_this_turn = []
# Process captured player pieces (possible loss condition) # Process captured player pieces (possible loss condition)
for piece in player_pieces_lost_this_turn: for piece in player_pieces_lost_this_turn:
if winConditionManager: if winConditionManager:
winConditionManager.on_piece_lost(piece) winConditionManager.on_piece_lost(piece)
print(player_pieces_lost_this_turn) print(player_pieces_lost_this_turn)
player_pieces_lost_this_turn = []
func _on_win_condition_met(condition_data): func _on_win_condition_met(condition_data):
stateMachine.disable()
print("Win condition met: ", condition_data) print("Win condition met: ", condition_data)
recover_cards_from_player_pieces() recover_cards_from_player_pieces()
emit_signal("node_completed", { emit_signal("node_completed", {
@ -817,6 +823,7 @@ func _on_win_condition_met(condition_data):
# endRound() # endRound()
func _on_loss_condition_met(condition_data): func _on_loss_condition_met(condition_data):
stateMachine.disable()
print("Loss condition met: ", condition_data) print("Loss condition met: ", condition_data)
recover_cards_from_player_pieces() recover_cards_from_player_pieces()
emit_signal("node_completed", { emit_signal("node_completed", {
@ -988,7 +995,6 @@ func getPieceFenChar(piece: Pawn) -> String:
"Queen": fenChar = "q" "Queen": fenChar = "q"
"King": fenChar = "k" "King": fenChar = "k"
# In our system, Item_Color == 1 is white, 0 is black
return fenChar.to_upper() if piece.Item_Color == 0 else fenChar return fenChar.to_upper() if piece.Item_Color == 0 else fenChar
# Unused # Unused

View file

@ -265,41 +265,62 @@ func generate_boss_data(node):
# level_unit_distribution # level_unit_distribution
# current_max_level # current_max_level
var rng = float(node.level) / int(current_max_level) var rng = float(node.level) / int(current_max_level)
var game_type = "zerg"
var height = 6;
# (current_value, min_value, max_value, min_index, max_index) # (current_value, min_value, max_value, min_index, max_index)
var index = map_to_array_index(node.level, 2, current_max_level - 2, 1, level_unit_distribution.size() - 1); var index = map_to_array_index(node.level, 2, current_max_level - 2, 1, level_unit_distribution.size() - 1);
if game_type == "zerg":
index = 7
height = 7
# if game_type == "zerg":
# index = map_to_array_index(node.level, 5, current_max_level - 2, 1, level_unit_distribution.size() - 1);
var unit_string = level_unit_distribution[index] var unit_string = level_unit_distribution[index]
var pawn_string = "" var pawn_string = ""
var enemy_unit_depth = 3
for x in unit_string.length(): for x in unit_string.length():
pawn_string += "p" pawn_string += "p"
var height = 6;
# "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR"
var fen = ""; var fen = "";
if node.level > 7 and node.level <= 10: # "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR"
if node.level >= 7 and node.level <= 10:
height = node.level height = node.level
enemy_unit_depth = 3
elif node.level > 10: elif node.level > 10:
height = 10 height = 10
for x in height - 2: enemy_unit_depth = 4
for x in height - enemy_unit_depth:
if x == 0: if x == 0:
fen += unit_string + "/" fen += unit_string + "/"
elif x == 1: elif x == 1:
fen += pawn_string + "/" fen += pawn_string + "/"
# elif x == height - 3: # elif x == height - 3:
# for y in unit_string.length() - 1: # fen += "u"
# fen += "*" # # for y in unit_string.length() - 1:
# fen += "1/" # # fen += "*"
# fen += "u/"
else: else:
fen += str(unit_string.length()) + "/" fen += str(unit_string.length()) + "/"
fen += pawn_string.to_upper() + "/" + unit_string.to_upper()
if game_type == "zerg":
for x in enemy_unit_depth - 1:
fen += pawn_string.to_upper() + "/"
fen += pawn_string.to_upper()
else:
fen += pawn_string.to_upper() + "/" + unit_string.to_upper()
var fen_ending = " w KQkq - 0 1" var fen_ending = " w KQkq - 0 1"
# print("generate_chess_data ", fen + fen_ending) # print("generate_chess_data ", fen + fen_ending)
return { return {
"is_escape": node.metadata.is_escape if node.metadata.has("is_escape") else false, "is_escape": node.metadata.is_escape if node.metadata.has("is_escape") else false,
"fen": fen + fen_ending, "fen": fen + fen_ending,
"game_type": "chess", "game_type": game_type,
"win_condition": Utils.WinConditionType.CAPTURE_UNIT, "win_condition": Utils.WinConditionType.TURN_NUMBER,
"win_target_turn": 30,
"has_opponent": true,
"loss_target_unit": "King",
"loss_condition": Utils.LossConditionType.UNIT_LOST,
"reward": { "reward": {
"gold": 50 * node.level, "gold": 50 * node.level,
"cards": [], "cards": [],
@ -351,7 +372,7 @@ func generate_event_data(node):
elif node.level > 10: elif node.level > 10:
height = 10 height = 10
# var mazedata = generate_maze(width, height) # var mazedata = generate_maze(width, height)
var mazedata = generate_maze(16, 16) var mazedata = generate_maze(12, 12)
# print("**************************") # print("**************************")
# print("**************************") # print("**************************")
# print("**************************") # print("**************************")
@ -391,7 +412,7 @@ func generate_chess_data(node):
var height = 6; var height = 6;
# "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR" # "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR"
var fen = ""; var fen = "";
if node.level > 7 and node.level <= 10: if node.level > 8 and node.level <= 10:
height = node.level height = node.level
elif node.level > 10: elif node.level > 10:
height = 10 height = 10
@ -477,6 +498,7 @@ func generate_chess_data(node):
"game_type": "chess", "game_type": "chess",
"win_condition": win_condition, "win_condition": win_condition,
"loss_condition": loss_condition, "loss_condition": loss_condition,
"has_opponent": true,
"elo": node.elo, "elo": node.elo,
"reward": { "reward": {
"gold": 50 * node.level "gold": 50 * node.level

View file

@ -221,6 +221,7 @@ func count_enemy_pieces() -> int:
# Helper methods for game integration # Helper methods for game integration
func load_condition_from_metadata(metadata: Dictionary): func load_condition_from_metadata(metadata: Dictionary):
reset_conditions();
# print("load_condition_from_metadata ", metadata) # print("load_condition_from_metadata ", metadata)
if metadata.has("win_condition"): if metadata.has("win_condition"):
match metadata["win_condition"]: match metadata["win_condition"]:
@ -235,14 +236,14 @@ func load_condition_from_metadata(metadata: Dictionary):
Utils.WinConditionType.BOARD_CLEARED: Utils.WinConditionType.BOARD_CLEARED:
set_win_condition(Utils.WinConditionType.BOARD_CLEARED) set_win_condition(Utils.WinConditionType.BOARD_CLEARED)
Utils.WinConditionType.TURN_NUMBER: Utils.WinConditionType.TURN_NUMBER:
set_win_condition(Utils.WinConditionType.TURN_NUMBER, {"target_turn": metadata.get("target_turn", 20)}) set_win_condition(Utils.WinConditionType.TURN_NUMBER, {"target_turn": metadata.get("win_target_turn", 20)})
if metadata.has("loss_condition"): if metadata.has("loss_condition"):
match metadata["loss_condition"]: match metadata["loss_condition"]:
Utils.LossConditionType.UNIT_LOST: Utils.LossConditionType.UNIT_LOST:
set_loss_condition(Utils.LossConditionType.UNIT_LOST, {"unit": "King"}) set_loss_condition(Utils.LossConditionType.UNIT_LOST, {"unit": "King"})
Utils.LossConditionType.TURN_NUMBER: Utils.LossConditionType.TURN_NUMBER:
set_loss_condition(Utils.LossConditionType.TURN_NUMBER, {"turn_limit": metadata.get("turn_limit", 50)}) set_loss_condition(Utils.LossConditionType.TURN_NUMBER, {"turn_limit": metadata.get("loss_turn_limit", 50)})
# Debug methods # Debug methods

View file

@ -15,7 +15,6 @@ func _ready() -> void:
add_child(stateDelay) add_child(stateDelay)
func enter(_previous: String, _data := {}) -> void: func enter(_previous: String, _data := {}) -> void:
game.moveCount += 1;
print("ENTERING STATE ", Constants.BLACK_TURN) print("ENTERING STATE ", Constants.BLACK_TURN)
game.currentPlayer = game.BLACK game.currentPlayer = game.BLACK

View file

@ -3,6 +3,7 @@ extends "res://Systems/StateMachine/ChessGameState.gd"
func enter(_previous: String, data := {}) -> void: func enter(_previous: String, data := {}) -> void:
print("ENTERING STATE ", Constants.CLEANUP, data) print("ENTERING STATE ", Constants.CLEANUP, data)
game.moveCount += 1;
if "endCondition" in data: if "endCondition" in data:
finished.emit(Constants.ROUND_END) finished.emit(Constants.ROUND_END)
elif game.currentPlayer == game.WHITE and game.has_opponent: elif game.currentPlayer == game.WHITE and game.has_opponent:

View file

@ -48,8 +48,8 @@ func check_win_conditions() -> bool:
return true return true
Utils.WinConditionType.TURN_NUMBER: Utils.WinConditionType.TURN_NUMBER:
print("check_win_conditions ", "Utils.WinConditionType.TURN_NUMBER")
var target_turn = game.winConditionManager.win_condition_data.get("target_turn", 0) var target_turn = game.winConditionManager.win_condition_data.get("target_turn", 0)
print("check_win_conditions ", "Utils.WinConditionType.TURN_NUMBER ", target_turn , " ?= ", game.winConditionManager.turn_count )
if game.winConditionManager.turn_count >= target_turn: if game.winConditionManager.turn_count >= target_turn:
var condition_data = { var condition_data = {
"type": Utils.WinConditionType.TURN_NUMBER, "type": Utils.WinConditionType.TURN_NUMBER,

View file

@ -76,12 +76,14 @@ 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
print("HANDLING MOVEMENT ", location, " | ", last_selected, " | ", game.selectedNode)
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)
if node.has_piece():
print(node.get_piece())
var prev_last_selected = last_selected var prev_last_selected = last_selected
if !generated : if !generated :
if last_selected == null: if last_selected == null:
@ -140,7 +142,7 @@ func handleMovement(location: String, generated: bool = false) -> void:
game.getMovableAreas() game.getMovableAreas()
return return
if game.selectedNode == location and location == prev_last_selected: if !generated and game.selectedNode == location and location == prev_last_selected:
# print("CAN CLEAR SELECTION************* ", multiMoving, " !is_multi_moving ", !is_multi_moving) # print("CAN CLEAR SELECTION************* ", multiMoving, " !is_multi_moving ", !is_multi_moving)
if !is_multi_moving and multiMoving == "": if !is_multi_moving and multiMoving == "":
print("CLEAR SELECTION*************") print("CLEAR SELECTION*************")

View file

@ -8,6 +8,7 @@ class_name StateMachine extends Node
@onready var parent = get_parent() @onready var parent = get_parent()
var previouseState = null var previouseState = null
var disabled = true
@onready var stateString: RichTextLabel = owner.get_node("StateLabel") @onready var stateString: RichTextLabel = owner.get_node("StateLabel")
@ -15,6 +16,7 @@ func _ready() -> void:
print("Ready Statemachine") print("Ready Statemachine")
func start() -> void: func start() -> void:
disabled = false
for stateNode: ChessGameState in find_children("*", "ChessGameState"): for stateNode: ChessGameState in find_children("*", "ChessGameState"):
stateNode.game = owner stateNode.game = owner
stateNode.finished.connect(transitionToNextState) stateNode.finished.connect(transitionToNextState)
@ -22,7 +24,12 @@ func start() -> void:
await owner.ready await owner.ready
state.enter("") state.enter("")
func enter() -> void: func enter() -> void:
disabled = false
state.enter("") state.enter("")
func enable() -> void:
disabled = false
func disable() -> void:
disabled = true
func unhandledInput(event: InputEvent) -> void: func unhandledInput(event: InputEvent) -> void:
# print("StateMachine received input:", event) # print("StateMachine received input:", event)
@ -33,8 +40,15 @@ func process(delta: float) -> void: state.update(delta)
func transitionToNextState(targetStatePath: String, data: Dictionary = {}) -> void: func transitionToNextState(targetStatePath: String, data: Dictionary = {}) -> void:
if disabled:
previouseState = state.name
state.exit()
state = get_node(Constants.ROUND_END)
stateString.text = Constants.ROUND_END;
state.enter(previouseState, data)
print("DISABLED TRANSITION TO: ", targetStatePath, "Going to", Constants.ROUND_END)
return
print("TRANSITIONING TO: ", targetStatePath) print("TRANSITIONING TO: ", targetStatePath)
if not has_node(targetStatePath): if not has_node(targetStatePath):
printerr(owner.name + ": Trying to transition to state " + targetStatePath + " but it does not exist.") printerr(owner.name + ": Trying to transition to state " + targetStatePath + " but it does not exist.")