Fixed tests. Need to check for damage from AI code

This commit is contained in:
2026-06-11 16:39:58 -06:00
parent df68358a2e
commit 6d2c2162f0
9 changed files with 149 additions and 78 deletions
+20 -5
View File
@@ -1,7 +1,7 @@
# frozen_string_literal: true
# Nathan Hinton, 22 Dec 2025
# Game server for the space game
# Space game server engine.
# Coordinates game state, player connections, and world simulation.
require 'game/player'
require 'game/planet'
@@ -160,7 +160,7 @@ module Game
home = free_planets.sample
player = Player.new(player_id || SecureRandom.hex, faction)
player.create_new(
player.set_resources(
@player_defaults['credits'],
@player_defaults['metal'],
@player_defaults['crystals'],
@@ -230,8 +230,8 @@ module Game
# @param msg [String] The error message
# @return [String] JSON-encoded error response
#
def error_response(request_id, msg)
{ 'type' => 'error', 'request_id' => id, 'payload' => msg }.to_json
def error_response(msg)
{ 'type' => 'error', 'request_id' => -1, 'payload' => msg }.to_json
end
##
@@ -376,10 +376,20 @@ module Game
@players.find { |p| p.player_id == player_id } || false
end
# Loads players from a list of IDs.
# @param ids [Array<String>] list of player IDs.
# @return [Array<Player>] the loaded players.
def load_players(ids)
ids.map { |id| Player.load_from_id(id) }
end
# Loads planets from a configuration list or creates new ones.
# @param planets [Integer, Array<String>] number of planets to create or list of planet IDs.
# @return [Array<Planet>] the loaded or created planets.
def load_planets(planets)
if planets.is_a?(Integer) # legacy config - integer means “create N”
Array.new(planets) { Planet.new }
@@ -388,6 +398,11 @@ module Game
end
end
# Loads ships from a list of IDs.
# @param ids [Array<String>] list of ship IDs.
# @return [Array<Ship>] the loaded ships.
def load_ships(ids)
ids.map { |id| Ship.load_from_id(id) } # Ship is a placeholder
end