Dinger: Kartenspiel in Godot 4.7
Elemente, Kombos, Fallen, KI mit Vorausschau, Kampagne, Hotseat und Netzwerk, Werkstatt, Erfolge, Tagesaufgaben, Tests und Exporte. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QPgKvy5W9WRNFHjkm5QsHx
This commit is contained in:
65
tests/net_bot.gd
Normal file
65
tests/net_bot.gd
Normal file
@@ -0,0 +1,65 @@
|
||||
extends Node
|
||||
## Test-Mitspieler: tritt einem Host bei und spielt einfache Züge.
|
||||
## godot --path . tests/net_bot.tscn -- --ip=127.0.0.1 --name=Bot
|
||||
|
||||
var net: Net
|
||||
var seat := -1
|
||||
var game: Game
|
||||
var t := 0.0
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
var ip := "127.0.0.1"
|
||||
var bot_name := "Bot"
|
||||
for a in OS.get_cmdline_user_args():
|
||||
if a.begins_with("--ip="):
|
||||
ip = a.substr(5)
|
||||
if a.begins_with("--name="):
|
||||
bot_name = a.substr(7)
|
||||
net = Net.new()
|
||||
net.name = "Net"
|
||||
get_tree().root.add_child.call_deferred(net)
|
||||
net.my_name = bot_name
|
||||
net.my_deck = Profile.starter().deck.duplicate()
|
||||
net.started.connect(func(s): seat = s)
|
||||
net.snapshot_received.connect(_on_snapshot)
|
||||
net.ended.connect(func(_r): get_tree().quit())
|
||||
await get_tree().process_frame
|
||||
net.join(ip)
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
t += delta
|
||||
if t > 180.0 or FileAccess.file_exists("user://bot_quit"):
|
||||
net.leave()
|
||||
get_tree().quit()
|
||||
|
||||
|
||||
func _on_snapshot(snap: Dictionary) -> void:
|
||||
game = Game.from_snapshot(snap)
|
||||
if game.winner != "":
|
||||
await get_tree().create_timer(1.0).timeout
|
||||
get_tree().quit()
|
||||
return
|
||||
if game.current_idx != seat:
|
||||
return
|
||||
var me: Game.Player = game.players[seat]
|
||||
if not me.mulligan_done and me.turns == 1:
|
||||
net.send_action({"type": "mulligan", "hand": []})
|
||||
return
|
||||
for i in me.hand.size():
|
||||
var card: Cards.Card = me.hand[i]
|
||||
if game.can_play(me, card)[0] and card.target_type() == "":
|
||||
net.send_action({"type": "play", "hand": i, "target": null})
|
||||
return
|
||||
for cr in me.board:
|
||||
if cr.can_attack():
|
||||
for e in game.enemies_of(me):
|
||||
if game.can_attack(cr, e)[0]:
|
||||
net.send_action({"type": "attack", "uid": cr.uid, "target": {"kind": "player", "index": game.players.find(e)}})
|
||||
return
|
||||
for c in e.board:
|
||||
if game.can_attack(cr, c)[0]:
|
||||
net.send_action({"type": "attack", "uid": cr.uid, "target": {"kind": "creature", "uid": c.uid}})
|
||||
return
|
||||
net.send_action({"type": "end"})
|
||||
Reference in New Issue
Block a user