フロントエンドプレイアブル
This commit is contained in:
35
test_api_v3.rb
Normal file
35
test_api_v3.rb
Normal file
@@ -0,0 +1,35 @@
|
||||
client = GameApiClient.new
|
||||
turn1 = Turn.find_by(number: 1)
|
||||
|
||||
def get_units(gs)
|
||||
return {} unless gs.is_a?(Hash)
|
||||
gs = gs['game_state'] if gs.has_key?('game_state')
|
||||
units = {}
|
||||
if gs['powers'].is_a?(Hash)
|
||||
gs['powers'].each do |power, data|
|
||||
units[power] = data['units']
|
||||
end
|
||||
end
|
||||
units
|
||||
end
|
||||
|
||||
if turn1
|
||||
puts "Sending process request for Turn 1..."
|
||||
res = client.api_calculate_process(turn1.game_state, turn1.orders || {})
|
||||
|
||||
if res
|
||||
new_gs = res['game_state']
|
||||
puts "Response Phase: #{new_gs&.dig('phase')}"
|
||||
|
||||
puts "Units in Response game_state:"
|
||||
units = get_units(new_gs)
|
||||
puts units.inspect
|
||||
|
||||
puts "\nSending possible_orders request using this response..."
|
||||
pos = client.api_calculate_possible_orders(new_gs, by_power: true)
|
||||
puts "Possible Orders for AUSTRIA:"
|
||||
puts (pos&.dig('possible_orders', 'AUSTRIA') || "None").inspect[0..500]
|
||||
else
|
||||
puts "Process failed."
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user