Skip to content

Commit

Permalink
utils for visualizing games
Browse files Browse the repository at this point in the history
  • Loading branch information
pamop committed Jun 27, 2024
1 parent 29f43a6 commit 8ffb4d2
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 58 deletions.
121 changes: 63 additions & 58 deletions utils/ascii_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import numpy as np
import csv
import pandas as pd
from datetime import datetime
import os

def get_target_loc(target, legal_moves):
moves = []
Expand All @@ -17,7 +17,8 @@ def get_target_loc(target, legal_moves):

def get_items_from_layer(layer, coloronly = False): #twelve possible layers, "Items00" thru "Items11"
# configure how to get list of veggies from a given starting setup (one of the twelve object layers)
fname = "../modeling/config/objectLayers.csv"
# print(os.getcwd())
fname = os.getcwd() + "/utils/game_configs.csv"
objectlayers = {}

with open(fname, 'r') as data:
Expand Down Expand Up @@ -140,74 +141,78 @@ def print_mapstr(veglist, chars):
numLine = numLine.replace("values",colNums)
print(numLine)

def print_transcript(df, id, game):
thisgame = df[(df["id"]==id)][(df["gameNum"]==game)]

print("Showing game " + str(game) + " from player " + id)
def print_transcript(df, sesh, game):
thisgame = df[(df["session"]==sesh) & (df["gameNum"]==game)]

print("Showing game " + str(game) + " from session " + sesh)
print("Condition: " + thisgame["resourceCond"].iloc[0] + " " + thisgame["visibilityCond"].iloc[0] + " " + thisgame["costCond"].iloc[0])
print("Red BP capacity: " + str(thisgame["redBackpackSize"].iloc[0]) + ", Purple BP capacity: " + str(thisgame["purpleBackpackSize"].iloc[0]))
print("start time: " + str(datetime.fromtimestamp(thisgame["timestamp"].iloc[0]/1000)))
print("start time: " + str(datetime.fromtimestamp(thisgame["turnStartTimestamp"].iloc[0]/1000)))

# red starts at 'x':2, 'y':15
# purple starts at 'x':3, 'y':16
# chars = [(2,15,'R'),(3,16,'P')]
chars = [(thisgame["redXloc"].iloc[0],thisgame["redYloc"].iloc[0],'R'),(thisgame["purpleXloc"].iloc[0],thisgame["purpleYloc"].iloc[0],'P')]

veglist = get_items_from_layer(thisgame["objectLayer"].unique()[0])
print_mapstr(veglist, chars)

for i in sorted(thisgame['trial'].unique()):
trial = thisgame[thisgame['trial']==i].iloc[0]
# print char backpacks and farm box contents
print("\n*** turn" + str(trial['turnCount']) + " ***")
print("Event:" + trial["eventName"])

if trial['eventName']=="targetPicked":
# chars = [(thisgame["redXloc"].iloc[0],thisgame["redYloc"].iloc[0],'R'),(thisgame["purpleXloc"].iloc[0],thisgame["purpleYloc"].iloc[0],'P')]

# veglist = get_items_from_layer(thisgame["objectLayer"].unique()[0])
# print_mapstr(veglist, chars)

for i in sorted(thisgame['trialNum'].unique()):
trial = thisgame[thisgame['trialNum']==i].iloc[0] # one row of the dataframe
# print(trial['gameover'])

# print map current status
chars = [(trial["redXloc"],trial["redYloc"],'R'),(trial["purpleXloc"],trial["purpleYloc"],'P')]
veglist = get_items_from_string(trial["farmItems"])
print_mapstr(veglist, chars)

if trial['gameover']:
# end of game
print("END OF GAME!")
print("Red energy="+str(trial['redEnergy'])+", score=" + str(trial['redScore']) + ": BONUS="+str(trial['redPoints']))
print("Purple energy="+str(trial['purpleEnergy'])+", score=" + str(trial['purpleScore']) + ": BONUS="+str(trial['purplePoints']))
else:
# print char backpacks and farm box contents
print(trial['agent'] + "'s turn! ***")
print("Timestamp: " + str(datetime.fromtimestamp(trial["timestamp"]/1000)))
print("\n*** turn " + str(trial['turnCount'])+ ": " + trial['agent'] + "'s turn! ***")

# print("Timestamp: " + str(datetime.fromtimestamp(trial["decisionMadeTimestamp"]/1000)))
print("red backpack: " + str(trial["redBackpack"]))
print("purple backpack: " + str(trial["purpleBackpack"]))
print("current box: " + str(trial["farmBox"]))
print(chars)

charid = 0 if trial['agent']=="red" else 1
otherplayerid = 1 if charid==0 else 0

print(trial['agent'] + " player picks " + trial['target'])


elif trial['eventName']=="objectEncountered":
print("harvest box: " + str(trial["farmBox"]))
# print(chars)

# print current scores
print("Red energy="+str(trial['redEnergy'])+", score=" + str(trial['redScore']))
print("Purple energy="+str(trial['purpleEnergy'])+", score=" + str(trial['purpleScore']))

try:
chars = [(trial["redXloc"],trial["redYloc"],'R'),(trial["purpleXloc"],trial["purpleYloc"],'P')]
print(chars)
except:
# find target in legal moves to get the tile that they move to
x,y = get_target_loc(trial['target'], trial['legalMoves'])
if trial["target"]=="box":
# move out of the way of the box
x,y = x - 1, y + 2
if (chars[otherplayerid][0]==x and chars[otherplayerid][1]==y):
x,y = x + 1, y + 2

# move the corresponding character to their new location
if trial['agent']=="red":
chars[0]=(x,y,'R')
else:
chars[1]=(x,y,'P')
# print player choice
print(trial['agent'].capitalize() + " player picks " + trial['target'] + ". Response time: " + str(int(trial['responseTime'])) + "ms.")

# chars = [(trial["redXloc"],trial["redYloc"],'R'),(trial["purpleXloc"],trial["purpleYloc"],'P')]
# # print map current status
# veglist = get_items_from_string(trial["farmItems"])
# print_mapstr(veglist, chars)
# # try:
# chars = [(trial["redXloc"],trial["redYloc"],'R'),(trial["purpleXloc"],trial["purpleYloc"],'P')]
# print(chars)
# except:
# # find target in legal moves to get the tile that they move to
# x,y = get_target_loc(trial['target'], trial['legalMoves'])
# if trial["target"]=="box":
# # move out of the way of the box
# x,y = x - 1, y + 2
# if (chars[otherplayerid][0]==x and chars[otherplayerid][1]==y):
# x,y = x + 1, y + 2

# # move the corresponding character to their new location
# if trial['agent']=="red":
# chars[0]=(x,y,'R')
# else:
# chars[1]=(x,y,'P')

# print map current status
veglist = get_items_from_string(trial["farmItems"])
print_mapstr(veglist, chars)
elif "start" in trial['eventName']:
# print("Event:" + trial["eventName"])
print(" ")
else:
# end of game
print("END OF GAME!")
print("Red energy="+str(trial['redEnergy'])+", score=" + str(trial['redScore']) + ": BONUS="+str(trial['redPoints']))
print("Purple energy="+str(trial['purpleEnergy'])+", score=" + str(trial['purpleScore']) + ": BONUS="+str(trial['purplePoints']))
# # print map current status
# veglist = get_items_from_string(trial["farmItems"])
# print_mapstr(veglist, chars)


13 changes: 13 additions & 0 deletions utils/game_configs.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
objectLayer,farmItems
Items00,"['Tomato00(8,7) Turnip01(13,13) Turnip00(12,13) Strawberry01(8,8) Strawberry00(7,7) Eggplant00(12,14) Tomato01(7,8) Turnip02(13,14)']"
Items01,"['Tomato00(7,8) Turnip01(12,13) Turnip00(8,7) Strawberry01(8,8) Strawberry00(7,7) Eggplant00(12,14) Tomato01(13,13) Turnip02(13,14)']"
Items02,"['Tomato00(8,7) Turnip01(13,13) Turnip00(12,13) Strawberry02(8,8) Strawberry01(9,7) Strawberry00(7,7) Eggplant00(12,14) Tomato01(7,8)']"
Items03,"['Tomato00(8,7) Turnip01(13,13) Turnip00(12,13) Strawberry00(7,7) Eggplant01(12,14) Tomato01(7,8) Turnip02(13,14) Eggplant00(14,13)']"
Items04,"['Tomato04(9,13) Turnip02(14,15) Turnip00(11,7) Strawberry01(13,11) Eggplant03(13,15) Tomato01(6,6) Turnip01(6,10) Eggplant02(14,14) Strawberry00(6,5) Strawberry02(9,14) Tomato00(5,5) Tomato02(14,10) Eggplant00(10,8) Eggplant01(5,10)']"
Items05,"['Tomato02(5,10) Turnip02(14,15) Turnip00(11,7) Strawberry02(14,14) Eggplant03(13,15) Tomato01(10,8) Turnip01(6,10) Eggplant01(13,11) Strawberry00(6,5) Strawberry01(9,14) Tomato00(5,5) Tomato03(14,10) Eggplant00(6,6) Eggplant02(9,13)']"
Items06,"['Tomato00(13,13) Turnip01(8,7) Turnip00(7,7) Strawberry01(13,14) Strawberry00(12,13) Eggplant00(7,8) Tomato01(12,14) Turnip02(8,8)']"
Items07,"['Tomato01(12,14) Turnip00(7,7) Turnip02(13,13) Strawberry01(13,14) Strawberry00(12,13) Eggplant00(7,8) Tomato00(8,7) Turnip01(8,8)']"
Items08,"['Eggplant01(7,8) Eggplant00(8,7) Turnip00(7,7) Turnip02(8,8) Turnip01(9,7) Tomato00(12,14) Strawberry00(12,13) Strawberry01(13,13)']"
Items09,"['Eggplant01(7,8) Eggplant00(8,7) Turnip00(7,7) Tomato01(12,14) Tomato00(14,13) Strawberry00(12,13) Strawberry01(13,13) Strawberry02(13,14)']"
Items10,"['Tomato01(5,10) Tomato00(10,8) Strawberry01(6,10) Strawberry00(11,7) Tomato03(13,15) Tomato02(14,14) Strawberry02(14,15) Turnip01(13,11) Turnip02(9,14) Turnip00(6,5) Eggplant02(14,10) Eggplant03(9,13) Eggplant00(5,5) Eggplant01(6,6)']"
Items11,"['Eggplant00(5,5) Eggplant02(5,10) Eggplant01(10,8) Eggplant03(14,10) Turnip00(6,5) Turnip01(9,14) Turnip02(14,14) Tomato00(6,6) Tomato01(13,11) Tomato03(13,15) Tomato02(9,13) Strawberry01(6,10) Strawberry00(11,7) Strawberry02(14,15)']"

0 comments on commit 8ffb4d2

Please sign in to comment.