clamped zerg servival turn goal

This commit is contained in:
2ManyProjects 2025-03-10 02:44:14 -05:00
parent 21688aa11b
commit 6e5272e37d
7 changed files with 92 additions and 18 deletions

View file

@ -62,6 +62,10 @@ var has_opponent = true;
var captured_pieces_this_turn: Array = []
var player_pieces_lost_this_turn: Array = []
var winConditionManager: WinConditionManager = null
var boss_type = null
var boss_turn_additional = null
var boss_turn_index = null
# Export parameters
@ -108,6 +112,10 @@ func _on_new_game_requested(options = {}):
print("ChessGame received new_game_requested signal ", is_initialized)
captured_pieces_this_turn = []
player_pieces_lost_this_turn = []
boss_type = null
boss_turn_additional = null
boss_turn_index = null
moveCount = 1
turnIndicator.visible = true
has_opponent = true
@ -118,6 +126,11 @@ func _on_new_game_requested(options = {}):
currentFen = options.metadata.fen
if "elo" in options.metadata:
cpuElo = options.metadata.elo
if "boss_type" in options.metadata:
boss_type = options.metadata.boss_type
if "boss_turn_additional" in options.metadata and options.metadata.boss_turn_additional != null:
boss_turn_additional = options.metadata.boss_turn_additional
boss_turn_index = 0
if "has_opponent" in options.metadata:
has_opponent = options.metadata.has_opponent
if winConditionManager == null:
@ -521,7 +534,7 @@ func clearBoard() -> void:
child.remove_piece()
func updateTurnIndicator():
if Turn == 0: # White's turn
if currentPlayer == WHITE: # White's turn
turnIndicator.color = Color(1, 1, 1, 1) # White
else: # Black's turn
turnIndicator.color = Color(0, 0, 0, 1) # Black

View file

@ -186,6 +186,7 @@ func generate_map():
}
func _get_random_room_type(level, total_levels):
# return Utils.RoomType.BOSS
var boss_chance = 0.1 + (level / float(total_levels) * 0.1)
var shop_chance = 0.1 + (level / float(total_levels) * 0.05)
var event_chance = 0.05
@ -251,7 +252,7 @@ func generate_node_data(node):
Utils.RoomType.BOSS:
data.metadata = generate_boss_data(data)
Utils.RoomType.FINAL:
data.metadata = { "is_escape": true}
data.metadata = generate_chess_data(data)
Utils.RoomType.SHOP:
data.metadata = generate_shop_data(data)
Utils.RoomType.EVENT:
@ -265,18 +266,27 @@ func generate_boss_data(node):
# level_unit_distribution
# current_max_level
var rng = float(node.level) / int(current_max_level)
var game_type = "zerg"
var game_type = Utils.BossType.ZERG
var height = 6;
# (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);
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 special_unit = ""
var pawn_string = ""
var enemy_unit_depth = 3
if game_type == Utils.BossType.ZERG:
index = 7
height = 7
elif game_type == Utils.BossType.DOUBLETROUBLE:
index = 9
height = 9
elif game_type == Utils.BossType.WARLARD:
index = 10
height = 10
unit_string = "1rnbqkbnr1"
special_unit = "rnnnqkbbbr"
# if game_type == "zerg":
# index = map_to_array_index(node.level, 5, current_max_level - 2, 1, level_unit_distribution.size() - 1);
for x in unit_string.length():
pawn_string += "p"
@ -304,23 +314,56 @@ func generate_boss_data(node):
fen += str(unit_string.length()) + "/"
if game_type == "zerg":
if game_type == Utils.BossType.ZERG:
for x in enemy_unit_depth - 1:
fen += pawn_string.to_upper() + "/"
fen += pawn_string.to_upper()
elif game_type == Utils.BossType.WARLARD:
fen += pawn_string.to_upper() + "/" + special_unit.to_upper()
else:
fen += pawn_string.to_upper() + "/" + unit_string.to_upper()
var fen_ending = " w KQkq - 0 1"
# print("generate_chess_data ", fen + fen_ending)
# change condition
var win_condition = Utils.WinConditionType.TURN_NUMBER
var win_target_turn = null
var loss_target_unit = null
var win_target_unit = null
var boss_turn_additional = null
var loss_condition = Utils.LossConditionType.UNIT_LOST
if game_type == Utils.BossType.ZERG:
win_condition = Utils.WinConditionType.TURN_NUMBER
# smallest board = 2 x 6 = 12
# largest board = 10 x 12 = 120
# smallest turn target 10
# largest turn target 50
var roomSize = height * unit_string.length()
var clamped_value = clamp(roomSize, 12, 120)
var percentage = (clamped_value - 12) / (120 - 12)
win_target_turn = 10 + percentage * (50 - 10)
loss_target_unit = "King"
loss_condition = Utils.LossConditionType.UNIT_LOST
elif game_type == Utils.BossType.DOUBLETROUBLE:
boss_turn_additional = 2
win_condition = Utils.WinConditionType.CAPTURE_UNIT
win_target_unit = "King"
loss_target_unit = "King"
loss_condition = Utils.LossConditionType.UNIT_LOST
return {
"is_escape": node.metadata.is_escape if node.metadata.has("is_escape") else false,
"fen": fen + fen_ending,
"game_type": game_type,
"win_condition": Utils.WinConditionType.TURN_NUMBER,
"win_target_turn": 30,
"game_type": "chess",
"boss_type": game_type,
"has_opponent": true,
"loss_target_unit": "King",
"loss_condition": Utils.LossConditionType.UNIT_LOST,
"boss_turn_additional": boss_turn_additional,
"win_condition": win_condition,
"win_target_turn": win_target_turn,
"win_target_unit": win_target_unit,
"loss_target_unit": loss_target_unit,
"loss_condition": loss_condition,
"reward": {
"gold": 50 * node.level,
"cards": [],

View file

@ -226,7 +226,7 @@ func load_condition_from_metadata(metadata: Dictionary):
if metadata.has("win_condition"):
match metadata["win_condition"]:
Utils.WinConditionType.CAPTURE_UNIT:
set_win_condition(Utils.WinConditionType.CAPTURE_UNIT, {"unit": "King"})
set_win_condition(Utils.WinConditionType.CAPTURE_UNIT, {"unit": metadata.get("win_target_unit", "King")})
Utils.WinConditionType.TILE_REACHED:
# Get target tiles from metadata if available
@ -241,7 +241,7 @@ func load_condition_from_metadata(metadata: Dictionary):
if metadata.has("loss_condition"):
match metadata["loss_condition"]:
Utils.LossConditionType.UNIT_LOST:
set_loss_condition(Utils.LossConditionType.UNIT_LOST, {"unit": "King"})
set_loss_condition(Utils.LossConditionType.UNIT_LOST, {"unit": metadata.get("loss_target_unit", "King")})
Utils.LossConditionType.TURN_NUMBER:
set_loss_condition(Utils.LossConditionType.TURN_NUMBER, {"turn_limit": metadata.get("loss_turn_limit", 50)})

View file

@ -17,6 +17,7 @@ func _ready() -> void:
func enter(_previous: String, _data := {}) -> void:
print("ENTERING STATE ", Constants.BLACK_TURN)
game.currentPlayer = game.BLACK
game.updateTurnIndicator()
# Delay to avoid duplication during animation
if game.stockfishController:

View file

@ -3,10 +3,21 @@ extends "res://Systems/StateMachine/ChessGameState.gd"
func enter(_previous: String, data := {}) -> void:
print("ENTERING STATE ", Constants.CLEANUP, data)
game.moveCount += 1;
if "endCondition" in data:
finished.emit(Constants.ROUND_END)
elif game.currentPlayer == game.WHITE and game.has_opponent:
return
game.moveCount += 1;
if game.boss_turn_additional != null and game.currentPlayer == game.BLACK:
if game.boss_turn_index < game.boss_turn_additional:
game.boss_turn_index += 1
finished.emit(Constants.BLACK_TURN)
return
else:
game.boss_turn_index = 0
if game.currentPlayer == game.WHITE and game.has_opponent:
finished.emit(Constants.BLACK_TURN)
else:
finished.emit(Constants.WHITE_TURN)

View file

@ -3,4 +3,5 @@ extends "res://Systems/StateMachine/ChessGameState.gd"
func enter(_previous: String, _data := {}) -> void:
print("ENTERING STATE ", Constants.WHITE_TURN)
game.currentPlayer = game.WHITE
game.updateTurnIndicator()
finished.emit(Constants.HAND_SETUP)

View file

@ -67,6 +67,11 @@ enum RoomType {
EVENT
}
enum BossType {
ZERG,
DOUBLETROUBLE,
WARLARD,
}
enum WinConditionType {
CAPTURE_UNIT, # Default: King capture
BOARD_CLEARED, # Clear the board of all opponent pieces