Compare commits
5 Commits
3b07e6b3c5
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
80ebc655de | ||
|
|
3f183cdbd5 | ||
|
|
dba4974e9f | ||
|
|
0780fec1fb | ||
|
|
1b9266ff09 |
31
LICENSE.txt
Normal file
31
LICENSE.txt
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
MIT NON-AI License
|
||||||
|
|
||||||
|
Copyright (c) 2026, Nathaniel Bowman
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of the software and associated documentation files (the "Software"),
|
||||||
|
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions.
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
In addition, the following restrictions apply:
|
||||||
|
|
||||||
|
1. The Software and any modifications made to it may not be used for the purpose of training or improving machine learning algorithms,
|
||||||
|
including but not limited to artificial intelligence, natural language processing, or data mining. This condition applies to any derivatives,
|
||||||
|
modifications, or updates based on the Software code. Any usage of the Software in an AI-training dataset is considered a breach of this License.
|
||||||
|
|
||||||
|
2. The Software may not be included in any dataset used for training or improving machine learning algorithms,
|
||||||
|
including but not limited to artificial intelligence, natural language processing, or data mining.
|
||||||
|
|
||||||
|
3. Any person or organization found to be in violation of these restrictions will be subject to legal action and may be held liable
|
||||||
|
for any damages resulting from such use.
|
||||||
|
|
||||||
|
4. This software repository contains open-source software licenses that can be modified and used to derive other software licenses.
|
||||||
|
However, no derivative, modification or update is allowed to remove the licensing conditions that forbid the use of that derivative
|
||||||
|
for the purpose of training, or improving machine learning algorithms, including but not limited to artificial intelligence,
|
||||||
|
natural language processing, or data mining.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||||
|
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||||
|
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
@@ -55,6 +55,16 @@ class Gameplay():
|
|||||||
(research,)))
|
(research,)))
|
||||||
|
|
||||||
|
|
||||||
|
def queue_villagers_by_task_list(self, from_time, initial_tasks):
|
||||||
|
train_time = self.world.build_times.build_times[Units.VILLAGER]
|
||||||
|
|
||||||
|
if not isinstance(initial_tasks, list):
|
||||||
|
initial_tasks = [initial_tasks]
|
||||||
|
|
||||||
|
for i in range(len(initial_tasks)):
|
||||||
|
self.queue_villager(from_time + i*train_time, initial_tasks[i])
|
||||||
|
|
||||||
|
|
||||||
def queue_villagers_over_time(self, from_time, until_time, initial_task):
|
def queue_villagers_over_time(self, from_time, until_time, initial_task):
|
||||||
train_time = self.world.build_times.build_times[Units.VILLAGER]
|
train_time = self.world.build_times.build_times[Units.VILLAGER]
|
||||||
duration = max(0, until_time - from_time)
|
duration = max(0, until_time - from_time)
|
||||||
@@ -105,8 +115,9 @@ class Gameplay():
|
|||||||
(old_task, new_task, count,)))
|
(old_task, new_task, count,)))
|
||||||
|
|
||||||
|
|
||||||
def add_task_to_work_queue(self, action_time, task):
|
def add_task_to_work_queue(self, action_time, task, **kwargs):
|
||||||
self._check_time(action_time)
|
self._check_time(action_time)
|
||||||
|
task = (task, kwargs)
|
||||||
self.actions[action_time].append((self.world.add_task_to_work_queue,
|
self.actions[action_time].append((self.world.add_task_to_work_queue,
|
||||||
(task,)))
|
(task,)))
|
||||||
|
|
||||||
|
|||||||
@@ -16,14 +16,14 @@ class Housing():
|
|||||||
if world.get_effective_population() + required > pop_space:
|
if world.get_effective_population() + required > pop_space:
|
||||||
raise YallGotHousedException
|
raise YallGotHousedException
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def check_housing_safe(self, world, thing):
|
def check_housing_safe(self, world, thing):
|
||||||
try:
|
try:
|
||||||
self.check_housing(world, thing)
|
return self.check_housing(world, thing)
|
||||||
except YallGotHousedException:
|
except YallGotHousedException:
|
||||||
return False
|
return False
|
||||||
else:
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|||||||
@@ -181,7 +181,9 @@ class World():
|
|||||||
|
|
||||||
|
|
||||||
def add_task_to_work_queue(self, task, **kwargs):
|
def add_task_to_work_queue(self, task, **kwargs):
|
||||||
self.villager_work_queue.append((task, kwargs))
|
if isinstance(task, Tasks):
|
||||||
|
task = (task, kwargs)
|
||||||
|
self.villager_work_queue.append(task)
|
||||||
self._assign_to_villagers_from_work_queue()
|
self._assign_to_villagers_from_work_queue()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
224
tests/test.py
224
tests/test.py
@@ -92,6 +92,39 @@ class TestWorld(unittest.TestCase):
|
|||||||
self.assertResourcesMatch([150, new_wood, 100, 200], game.world)
|
self.assertResourcesMatch([150, new_wood, 100, 200], game.world)
|
||||||
|
|
||||||
|
|
||||||
|
def test_wood_stale_camp(self):
|
||||||
|
game = Gameplay()
|
||||||
|
|
||||||
|
wood_amount_per_camp = 1000
|
||||||
|
|
||||||
|
wood_rate_times_60 = 23.4
|
||||||
|
wood_rate_decrease = 0.85
|
||||||
|
slow_wood_rate_times_60 = wood_rate_times_60*wood_rate_decrease
|
||||||
|
|
||||||
|
game.world._add_building(Buildings.LUMBERCAMP, {}, {})
|
||||||
|
game.assign_villager(1, Tasks.IDLE, Tasks.WOOD)
|
||||||
|
|
||||||
|
game.play_until(60)
|
||||||
|
new_wood = 200 + wood_rate_times_60
|
||||||
|
self.assertResourcesMatch([200, new_wood, 100, 200], game.world)
|
||||||
|
|
||||||
|
camp_expires = 60*wood_amount_per_camp/wood_rate_times_60
|
||||||
|
|
||||||
|
game.play_until(camp_expires)
|
||||||
|
new_wood = 200 + wood_rate_times_60*(camp_expires/60)
|
||||||
|
self.assertResourcesMatch([200, new_wood, 100, 200], game.world)
|
||||||
|
self.assertResourcesMatch([200,
|
||||||
|
200 + wood_amount_per_camp,
|
||||||
|
100,
|
||||||
|
200],
|
||||||
|
game.world)
|
||||||
|
|
||||||
|
game.play_until(camp_expires + 60)
|
||||||
|
new_wood += slow_wood_rate_times_60
|
||||||
|
|
||||||
|
self.assertResourcesMatch([200, new_wood, 100, 200], game.world)
|
||||||
|
|
||||||
|
|
||||||
def test_good_villager_task_assign(self):
|
def test_good_villager_task_assign(self):
|
||||||
game = Gameplay()
|
game = Gameplay()
|
||||||
game.assign_villager(5, Tasks.IDLE, Tasks.SHEEP)
|
game.assign_villager(5, Tasks.IDLE, Tasks.SHEEP)
|
||||||
@@ -136,6 +169,18 @@ class TestWorld(unittest.TestCase):
|
|||||||
self.assertTrue(Buildings.LUMBERCAMP in game.world.buildings)
|
self.assertTrue(Buildings.LUMBERCAMP in game.world.buildings)
|
||||||
|
|
||||||
|
|
||||||
|
def test_build_lumber_camp_three_villagers(self):
|
||||||
|
lc_build_time = 35
|
||||||
|
lc_build_time_three_vils = 3*lc_build_time/(3 + 2)
|
||||||
|
|
||||||
|
game = Gameplay()
|
||||||
|
game.build(0, Buildings.LUMBERCAMP, [Tasks.IDLE]*3, [Tasks.IDLE]*3)
|
||||||
|
game.play_until(lc_build_time_three_vils - 1)
|
||||||
|
self.assertTrue(Buildings.LUMBERCAMP not in game.world.buildings)
|
||||||
|
game.play_until(lc_build_time_three_vils)
|
||||||
|
self.assertTrue(Buildings.LUMBERCAMP in game.world.buildings)
|
||||||
|
|
||||||
|
|
||||||
def test_building_adds_gatherable(self):
|
def test_building_adds_gatherable(self):
|
||||||
lc_build_time = 35
|
lc_build_time = 35
|
||||||
|
|
||||||
@@ -899,3 +944,182 @@ class TestWorld(unittest.TestCase):
|
|||||||
100,
|
100,
|
||||||
200],
|
200],
|
||||||
game.world)
|
game.world)
|
||||||
|
|
||||||
|
|
||||||
|
def test_queue_with_task_list(self):
|
||||||
|
game = Gameplay()
|
||||||
|
|
||||||
|
task_build_lumber = (Tasks.BUILD,
|
||||||
|
{'building': Buildings.LUMBERCAMP,
|
||||||
|
'villagers_to': Tasks.WOOD})
|
||||||
|
|
||||||
|
build_order = [
|
||||||
|
Tasks.SHEEP,
|
||||||
|
Tasks.SHEEP,
|
||||||
|
Tasks.SHEEP,
|
||||||
|
task_build_lumber,
|
||||||
|
]
|
||||||
|
|
||||||
|
game.queue_villagers_by_task_list(0, build_order)
|
||||||
|
game.assign_villager(0, Tasks.IDLE, Tasks.SHEEP)
|
||||||
|
game.build(0, Buildings.HOUSE, Tasks.IDLE, Tasks.SHEEP)
|
||||||
|
game.build(0, Buildings.HOUSE, Tasks.IDLE, Tasks.SHEEP)
|
||||||
|
|
||||||
|
game.play_until_last_action(extra_time=(25 + 35 + 60))
|
||||||
|
|
||||||
|
self.assertEqual(4, len(game.world.buildings))
|
||||||
|
|
||||||
|
train = 25
|
||||||
|
build_lumber = 35
|
||||||
|
build_house = 25
|
||||||
|
|
||||||
|
duration = 4*train + build_lumber + 60
|
||||||
|
|
||||||
|
sheep_rate_per_60 = 19.8
|
||||||
|
|
||||||
|
vil0 = sheep_rate_per_60*(duration/60)
|
||||||
|
vil1 = sheep_rate_per_60*((duration - build_house)/60)
|
||||||
|
vil2 = vil1
|
||||||
|
vil3 = sheep_rate_per_60*((duration - train)/60)
|
||||||
|
vil4 = sheep_rate_per_60*((duration - 2*train)/60)
|
||||||
|
vil5 = sheep_rate_per_60*((duration - 3*train)/60)
|
||||||
|
|
||||||
|
gathered_food = vil0 + vil1 + vil2 + vil3 + vil4 + vil5
|
||||||
|
|
||||||
|
wood_rate_per_60 = 23.4
|
||||||
|
gathered_wood = wood_rate_per_60
|
||||||
|
|
||||||
|
self.assertResourcesMatch([gathered_food,
|
||||||
|
50 + gathered_wood,
|
||||||
|
100,
|
||||||
|
200],
|
||||||
|
game.world)
|
||||||
|
|
||||||
|
|
||||||
|
def test_production_queue_two_units(self):
|
||||||
|
game = Gameplay()
|
||||||
|
|
||||||
|
game.world._add_building(Buildings.BARRACKS, {}, {})
|
||||||
|
game.world._add_building(Buildings.HOUSE, {}, {})
|
||||||
|
|
||||||
|
training = 21
|
||||||
|
|
||||||
|
game.queue_unit(0, Units.MILITIA)
|
||||||
|
game.queue_unit(0, Units.MILITIA)
|
||||||
|
|
||||||
|
game.play_until(1)
|
||||||
|
self.assertEqual(4, game.world.population)
|
||||||
|
|
||||||
|
game.play_until(training)
|
||||||
|
self.assertEqual(5, game.world.population)
|
||||||
|
|
||||||
|
game.play_until(training + 10)
|
||||||
|
self.assertEqual(5, game.world.population)
|
||||||
|
|
||||||
|
game.play_until(2*training)
|
||||||
|
self.assertEqual(6, game.world.population)
|
||||||
|
|
||||||
|
|
||||||
|
def test_production_queue_new_building(self):
|
||||||
|
game = Gameplay()
|
||||||
|
|
||||||
|
game.world._add_building(Buildings.BARRACKS, {}, {})
|
||||||
|
game.world._add_building(Buildings.HOUSE, {}, {})
|
||||||
|
|
||||||
|
training = 21
|
||||||
|
|
||||||
|
game.queue_unit(0, Units.MILITIA)
|
||||||
|
game.queue_unit(0, Units.MILITIA)
|
||||||
|
|
||||||
|
game.play_until(10)
|
||||||
|
game.world._add_building(Buildings.BARRACKS, {}, {})
|
||||||
|
|
||||||
|
game.play_until(training)
|
||||||
|
self.assertEqual(5, game.world.population)
|
||||||
|
|
||||||
|
game.play_until(training + 10)
|
||||||
|
self.assertEqual(6, game.world.population)
|
||||||
|
|
||||||
|
|
||||||
|
def test_production_queue_new_housing(self):
|
||||||
|
game = Gameplay()
|
||||||
|
|
||||||
|
game.world._add_building(Buildings.BARRACKS, {}, {})
|
||||||
|
game.set_housed_is_error(0, False)
|
||||||
|
|
||||||
|
training = 21
|
||||||
|
|
||||||
|
game.queue_unit(0, Units.MILITIA)
|
||||||
|
game.queue_unit(0, Units.MILITIA)
|
||||||
|
|
||||||
|
game.play_until(3*training)
|
||||||
|
self.assertEqual(5, game.world.population)
|
||||||
|
|
||||||
|
game.world._add_building(Buildings.HOUSE, {}, {})
|
||||||
|
game.play_until(4*training)
|
||||||
|
self.assertEqual(6, game.world.population)
|
||||||
|
|
||||||
|
|
||||||
|
def test_research_bit_axe(self):
|
||||||
|
game = Gameplay()
|
||||||
|
|
||||||
|
game.world.age = Ages.FEUDAL
|
||||||
|
|
||||||
|
wood_amount_per_camp = 1000
|
||||||
|
|
||||||
|
wood_rate_times_60 = 23.4
|
||||||
|
bit_axe_mult = 1.2
|
||||||
|
wood_rate_times_60 *= bit_axe_mult
|
||||||
|
|
||||||
|
bit_axe_time = 25
|
||||||
|
|
||||||
|
wood_rate_decrease = 0.85
|
||||||
|
slow_wood_rate_times_60 = wood_rate_times_60*wood_rate_decrease
|
||||||
|
|
||||||
|
game.world._add_building(Buildings.LUMBERCAMP, {}, {})
|
||||||
|
game.queue_research(0, Research.DOUBLEBITAXE)
|
||||||
|
|
||||||
|
game.assign_villager(bit_axe_time, Tasks.IDLE, Tasks.WOOD)
|
||||||
|
|
||||||
|
game.play_until(bit_axe_time + 60)
|
||||||
|
new_wood = 150 + wood_rate_times_60
|
||||||
|
self.assertResourcesMatch([100, new_wood, 100, 200], game.world)
|
||||||
|
|
||||||
|
camp_duration = 60*wood_amount_per_camp/wood_rate_times_60
|
||||||
|
|
||||||
|
game.play_until(bit_axe_time + camp_duration)
|
||||||
|
new_wood = 150 + wood_rate_times_60*(camp_duration/60)
|
||||||
|
self.assertResourcesMatch([100, new_wood, 100, 200], game.world)
|
||||||
|
self.assertResourcesMatch([100,
|
||||||
|
150 + wood_amount_per_camp,
|
||||||
|
100,
|
||||||
|
200],
|
||||||
|
game.world)
|
||||||
|
|
||||||
|
game.play_until(bit_axe_time + camp_duration + 60)
|
||||||
|
new_wood += slow_wood_rate_times_60
|
||||||
|
|
||||||
|
self.assertResourcesMatch([100, new_wood, 100, 200], game.world)
|
||||||
|
|
||||||
|
|
||||||
|
def test_research_bit_axe_partial_start(self):
|
||||||
|
game = Gameplay()
|
||||||
|
|
||||||
|
wood_rate_times_60 = 23.4
|
||||||
|
bit_axe_mult = 1.2
|
||||||
|
|
||||||
|
bit_axe_time = 25
|
||||||
|
|
||||||
|
game.world.age = Ages.FEUDAL
|
||||||
|
game.world._add_building(Buildings.LUMBERCAMP, {}, {})
|
||||||
|
|
||||||
|
game.assign_villager(0, Tasks.IDLE, Tasks.WOOD)
|
||||||
|
game.queue_research(35, Research.DOUBLEBITAXE)
|
||||||
|
|
||||||
|
game.play_until(60)
|
||||||
|
new_wood = 150 + wood_rate_times_60
|
||||||
|
self.assertResourcesMatch([100, new_wood, 100, 200], game.world)
|
||||||
|
|
||||||
|
game.play_until(120)
|
||||||
|
new_wood = 150 + wood_rate_times_60*(1 + bit_axe_mult)
|
||||||
|
self.assertResourcesMatch([100, new_wood, 100, 200], game.world)
|
||||||
|
|||||||
Reference in New Issue
Block a user