update
This commit is contained in:
81
test_cli.gd
Normal file
81
test_cli.gd
Normal file
@@ -0,0 +1,81 @@
|
||||
extends Node
|
||||
const ORT := "/tmp/claude-1000/-home-arbeit-projects-pirate-dice/00de2cf5-7327-4fce-b543-2b4db6d3b775/scratchpad"
|
||||
var game: Node
|
||||
var rolle := ""
|
||||
var runden := 0
|
||||
var wuerfe := 0
|
||||
var genau := 0
|
||||
var _letzte_phase := ""
|
||||
var _rng := RandomNumberGenerator.new()
|
||||
func _ready() -> void:
|
||||
Engine.time_scale = 8.0
|
||||
_rng.randomize()
|
||||
rolle = OS.get_cmdline_user_args()[0]
|
||||
add_child(preload("res://scenes/main.tscn").instantiate())
|
||||
await get_tree().create_timer(0.3).timeout
|
||||
_lauf()
|
||||
func _find(n: Node, w: String) -> Node:
|
||||
if n.name == w: return n
|
||||
for c in n.get_children():
|
||||
var r := _find(c, w)
|
||||
if r != null: return r
|
||||
return null
|
||||
func _warte(cond: Callable, sek: float) -> bool:
|
||||
var t := 0.0
|
||||
while t < sek:
|
||||
if cond.call(): return true
|
||||
await get_tree().create_timer(0.1).timeout
|
||||
t += 0.1
|
||||
return false
|
||||
func _lauf() -> void:
|
||||
if rolle == "host":
|
||||
Net.create_room("Host")
|
||||
await _warte(func(): return Net.room_code != "", 40.0)
|
||||
var f := FileAccess.open(ORT + "/code.txt", FileAccess.WRITE)
|
||||
f.store_string(Net.room_code); f.close()
|
||||
await _warte(func(): return Net.lobby.size() >= 2, 80.0)
|
||||
Net.request_start(1, 1)
|
||||
else:
|
||||
await _warte(func(): return FileAccess.file_exists(ORT + "/code.txt"), 80.0)
|
||||
await get_tree().create_timer(0.5).timeout
|
||||
Net.join_room(FileAccess.get_file_as_string(ORT + "/code.txt").strip_edges(), "Gast")
|
||||
await _warte(func(): game = _find(get_tree().root, "Game"); return game != null, 120.0)
|
||||
if game == null:
|
||||
print("%s: kein Spiel" % rolle); get_tree().quit(1); return
|
||||
var t := 0.0
|
||||
var gewartet := 0.0
|
||||
while t < 4400.0 and is_instance_valid(game) and game.phase != "over":
|
||||
await get_tree().create_timer(0.2).timeout; t += 0.2
|
||||
if not is_instance_valid(game): break
|
||||
if game.phase != _letzte_phase:
|
||||
_letzte_phase = game.phase
|
||||
if game.phase == "roll": runden += 1
|
||||
var me: int = game.local_seat
|
||||
if game.phase != "bid" or game.turn != me or not game.seats[me].alive:
|
||||
gewartet = 0.0; continue
|
||||
gewartet += 0.2
|
||||
if gewartet < 0.6: continue
|
||||
var hand: Array = game.hand.get(me, [])
|
||||
if not hand.is_empty() and (not BoosterDB.needs_bid(hand[0]) or not game.bid.is_empty()) and _rng.randf() < 0.7:
|
||||
game._on_booster_chosen(hand[0], 0)
|
||||
wuerfe += 1
|
||||
await get_tree().create_timer(2.5).timeout
|
||||
if not is_instance_valid(game) or game.turn != me or game.phase != "bid": continue
|
||||
var total := 0
|
||||
for s in game.seats: total += int(s.count)
|
||||
var a: Dictionary = DiceAI.choose_action(game.my_values, total, game.bid, false, _rng)
|
||||
if a.type == "challenge" and not game.bid.is_empty() and _rng.randf() < 0.3:
|
||||
a = {"type": "exact"}
|
||||
match a.type:
|
||||
"bid": game._on_bid_pressed(int(a.count), int(a.face))
|
||||
"challenge": game._on_challenge_pressed()
|
||||
"exact":
|
||||
game._on_exact_pressed(); genau += 1
|
||||
gewartet = -2.0
|
||||
if is_instance_valid(game):
|
||||
print("%s: Ende %s '%s' Platz=%d Runden=%d Wuerfe=%d Genau=%d" % [rolle, game.phase, game.banner, game.local_seat, runden, wuerfe, genau])
|
||||
for i in game.seats.size():
|
||||
print("%s: Platz %d %s count=%d alive=%s" % [rolle, i, game.seats[i].name, game.seats[i].count, game.seats[i].alive])
|
||||
else:
|
||||
print("%s: Spiel weg, Runden=%d" % [rolle, runden])
|
||||
get_tree().quit()
|
||||
Reference in New Issue
Block a user