feat: port tactical enemy AI
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
extends GutTest
|
||||
|
||||
const ActorState = preload("res://scripts/domain/actor_state.gd")
|
||||
const GameState = preload("res://scripts/domain/game_state.gd")
|
||||
const GridMapState = preload("res://scripts/domain/grid_map_state.gd")
|
||||
|
||||
func _state() -> GameState:
|
||||
var map := GridMapState.new(Vector2i(9, 5), GridMapState.CellKind.WALL)
|
||||
for y in range(1, 4):
|
||||
for x in range(1, 8):
|
||||
map.set_cell(Vector2i(x, y), GridMapState.CellKind.FLOOR)
|
||||
map.set_cell(Vector2i(4, 2), GridMapState.CellKind.WALL)
|
||||
map.set_cell(Vector2i(4, 1), GridMapState.CellKind.CLOSED_DOOR)
|
||||
var player := ActorState.new(&"player", Vector2i(7, 2), 20, 3)
|
||||
var hunter := ActorState.new(&"hunter", Vector2i(1, 2), 20, 2, &"enemy_goblin", {"ai": "aggressive", "vision_range": 8})
|
||||
var blocker := ActorState.new(&"blocker", Vector2i(2, 2), 20, 2, &"enemy_goblin", {"ai": "aggressive", "vision_range": 8})
|
||||
return GameState.new(map, player, {&"hunter": hunter, &"blocker": blocker})
|
||||
|
||||
func test_enemy_turn_paths_around_wall_and_closed_door_without_overlapping_an_ally() -> void:
|
||||
var state := _state()
|
||||
var results := state.try_player_action(Vector2i.DOWN)
|
||||
var moves := results.filter(func(result: TurnResult) -> bool: return result.kind == &"enemy_moved")
|
||||
assert_eq(moves.size(), 2)
|
||||
assert_eq(state.enemies[&"hunter"].cell, Vector2i(2, 2))
|
||||
assert_eq(state.enemies[&"blocker"].cell, Vector2i(2, 3))
|
||||
assert_ne(state.enemies[&"hunter"].cell, state.enemies[&"blocker"].cell)
|
||||
assert_ne(state.enemies[&"hunter"].cell, state.player.cell)
|
||||
assert_ne(state.map.get_cell(state.enemies[&"hunter"].cell), GridMapState.CellKind.CLOSED_DOOR)
|
||||
|
||||
func test_same_state_and_action_produce_identical_enemy_turn_results() -> void:
|
||||
var first := _state()
|
||||
var second := _state()
|
||||
var first_results := first.try_player_action(Vector2i.DOWN)
|
||||
var second_results := second.try_player_action(Vector2i.DOWN)
|
||||
assert_eq(_result_snapshot(first_results), _result_snapshot(second_results))
|
||||
assert_eq(first.enemies[&"hunter"].cell, second.enemies[&"hunter"].cell)
|
||||
assert_eq(first.enemies[&"blocker"].cell, second.enemies[&"blocker"].cell)
|
||||
|
||||
func _result_snapshot(results: Array[TurnResult]) -> Array:
|
||||
var snapshot: Array = []
|
||||
for result in results:
|
||||
snapshot.append([result.actor_id, result.kind, result.from_cell, result.to_cell, result.target_id, result.damage])
|
||||
return snapshot
|
||||
Reference in New Issue
Block a user