Skip to content

Commit

Permalink
Merge pull request #2 from nrecoder/Tanvi
Browse files Browse the repository at this point in the history
RunGame good to go Contains olivers investigations
  • Loading branch information
nrecoder authored Dec 4, 2024
2 parents 400648e + 5232852 commit a59d84b
Show file tree
Hide file tree
Showing 6 changed files with 2,962 additions and 797 deletions.
1,281 changes: 1,281 additions & 0 deletions modeling/Oliver Simulations.ipynb

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions modeling/farmgame.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,43 @@ def get_cost(self, action: Action) -> float:
n_steps += 3 # three because moving 1,2 away
return n_steps * self.stepcost

def all_objects_picked_up(self, player_color: str) -> bool:
player_items = [
item for item in self.items if item.color == player_color and item.type == ActionType.veggie
]
return all(item.status == "backpack" for item in player_items)

def get_steps(self, action: Action) -> int:
# no cost if no actions were available to the player
if action.type == ActionType.none:
return 0

# fixed cost if voluntarily passing
if action.type == ActionType.pillow or action.type == ActionType.timeout:
return self.pillowcost

# whose turn is it?
currentplayer = self.whose_turn()

# player moves to location. decrease energy by steps taken.
n_steps = utils.getManhattanDistance(currentplayer["loc"], action.loc)
# if going to the farm the player might have to step around the farm wall
if action.type == ActionType.box and currentplayer["loc"]["y"] <= self.farmbox.loc["y"]:
n_steps += 2
# if the player, other player and target are in the same row or column, and the other
# player is in the way, then add 2 sidesteps to go around them.
elif utils.is_in_line(currentplayer["loc"], self.other_player()["loc"], action.loc):
# Add 2 sidesteps if the other player is in the way. Somehow getPath doesn't cover this.
n_steps += 2

# decrease energy for move out of the way
if action.type == ActionType.box:
statuses = Counter(item.status for item in self.items)
# check if this move will end the game. If it does then the payer does not move away.
if "farm" in statuses or statuses["backpack"] > len(currentplayer["backpack"]["contents"]):
n_steps += 3 # three because moving 1,2 away
return n_steps

def take_action(self, action: Action, inplace=True) -> Farm:
if inplace:
new_state = self
Expand Down
4 changes: 3 additions & 1 deletion modeling/mcts.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ def run_simulation(self):

# everyone gets punished for slowness regardless of reward policy
# punish these bots for taking too long thoooooo
self.rewards[(player,q)]-= simstate.trial # TEMPORAL COST - THIS PENALTY MAY NEED TO BE TUNED
penalty_factor = 0.0 # Scale factor
self.rewards[(player, q)] -= penalty_factor * simstate.trial
# self.rewards[(player,q)]-= simstate.trial # TEMPORAL COST - THIS PENALTY MAY NEED TO BE TUNED

# here, we use string representation of hash rather than int that hash() itself gives
def hash_and_store(self, s):
Expand Down
Loading

0 comments on commit a59d84b

Please sign in to comment.