Add entity picking being adjustable for pure dt run and ga with dt run
In pure dt mode player can choose the same object like water any times in a row. In dt with ga mode player can't choose same object two times in a row.
This commit is contained in:
parent
1e4b44558c
commit
939c3f9072
@ -144,7 +144,7 @@ def doSimulation(weights, map, decisionTree: SurvivalDT):
|
||||
player.disableMovementTime()
|
||||
while player.alive:
|
||||
if player.movementTarget is None:
|
||||
target = decisionTree.pickEntity(player, map)
|
||||
target = decisionTree.pickEntity(player, map, pickForGa=True)
|
||||
player.gotoToTarget(target, map)
|
||||
player.update()
|
||||
fitness = player.movePoints
|
||||
|
@ -16,10 +16,11 @@ class SurvivalDT:
|
||||
def __init__(self, entityPickingDecisionTree: DecisionTree):
|
||||
self.entityPickingDecisionTree = entityPickingDecisionTree
|
||||
|
||||
def pickEntity(self, player, map):
|
||||
def pickEntity(self, player, map, pickForGa=False):
|
||||
"""
|
||||
Select an entity to become the next goal for the player.
|
||||
|
||||
:param pickForGa: If picking is done for genetic algorithm then pick can't be the same as last.
|
||||
:param player: Player object
|
||||
:param map: Map object
|
||||
"""
|
||||
@ -65,8 +66,14 @@ class SurvivalDT:
|
||||
dtRestPlaces,
|
||||
dtWaters)
|
||||
|
||||
"""
|
||||
If choice is being made for genetic algorithm then do not allow to pick same entity as before,
|
||||
because fitness is being calculated by travelled fields, not time being alive.
|
||||
So player shouldn't be standing and drinking water, but moving from one water field to another.
|
||||
"""
|
||||
if pickForGa:
|
||||
# If the choice happens to be the same as the last one pick something else.
|
||||
if choice == map.getEntityOnCoord(player.getFacingCoord()):
|
||||
if choice.interactable == map.getEntityOnCoord(player.getFacingCoord()):
|
||||
if treeDecision == SurvivalClassification.FOOD:
|
||||
dtFoods.remove(dtFoods[0])
|
||||
nearestDtFood = dtFoods[0]
|
||||
@ -79,16 +86,13 @@ class SurvivalDT:
|
||||
|
||||
currentSituation = SurvivalDTExample(None, playerStats.hungerAmount, playerStats.thirstAmount,
|
||||
playerStats.staminaAmount,
|
||||
dtFoods[0].dtDistanceFromPlayer, dtWaters[0].dtDistanceFromPlayer,
|
||||
dtRestPlaces[0].dtDistanceFromPlayer,
|
||||
nearestDtFood.dtDistanceFromPlayer, nearestDtWater.dtDistanceFromPlayer,
|
||||
nearestDtRest.dtDistanceFromPlayer,
|
||||
nearestDtFood.getDtDistanceFromOtherInteractable(nearestDtWater.interactable))
|
||||
|
||||
treeDecision, choice = self.__pickEntityAfterTreeDecision__(currentSituation, dtFoods,
|
||||
dtRestPlaces, dtWaters)
|
||||
|
||||
print("Tree choice: ")
|
||||
print(choice.getDescription())
|
||||
|
||||
return choice.interactable
|
||||
|
||||
def __pickEntityAfterTreeDecision__(self, currentSituation, dtFoods, dtRestPlaces, dtWaters):
|
||||
|
Loading…
Reference in New Issue
Block a user