import huggingface_hub import requests from gradio_client import Client client = Client("https://cogsphere-acogsphere.hf.space/") #client = Client("https://cognitivescience-acogspherea.hf.space/--replicas/k5l86/") #result = client.predict( # fn_index=1 #) #print(result) from python_actr import * log=log() class RPSChoice(Model): choice=None font='Arial 20' waiting=True def start(self): self.visible=True self.text=self.instructions def choose(self,option): if not self.waiting: return if option not in ['rock','paper','scissors']: return self.choice=option self.visible=False self.waiting=False # check to see if both players have made a choice if self.parent.choice1.choice is not None and self.parent.choice2.choice is not None: self.parent.determine_winner() def reset(self): self.text=self.instructions self.waiting=True self.visible=True self.choice=None class RockPaperScissors(Model): choice1=RPSChoice(x=0.5,y=0.2,instructions='Choose: Rock(1) Paper(2) Scissors(3)') choice2=RPSChoice(x=0.5,y=0.8,instructions='Choose: Rock(Z) Paper(X) Scissors(C)') result=Model(x=0.5,y=0.5,visible=False) score1=Model(text=0,x=0.9,y=0.1) score2=Model(text=0,x=0.9,y=0.9) trials=0 def key_pressed(self,key): if key=='1': self.choice1.choose('rock') if key=='2': self.choice1.choose('paper') if key=='3': self.choice1.choose('scissors') if key=='z': self.choice2.choose('rock') if key=='x': self.choice2.choose('paper') if key=='c': self.choice2.choose('scissors') def determine_winner(self): self.choice1.text=self.choice1.choice self.choice2.text=self.choice2.choice self.choice1.visible=True self.choice2.visible=True c1=self.choice1.choice c2=self.choice2.choice if c1==c2: self.result.text="Tie!" elif (c1=='rock' and c2=='scissors') or (c1=='paper' and c2=='rock') or (c1=='scissors' and c2=='paper'): self.result.text="Player 1 wins!" self.score1.text+=1 else: self.result.text="Player 2 wins!" self.score2.text+=1 self.result.visible=True yield 1 self.result.visible=False self.choice1.reset() self.choice2.reset() self.trials+=1 if self.trials>=24: scora=self.score1.text scorb=self.score2.text result = client.predict( "ACT-R playing RPS!", "Max to win: 24", "Model 1: " + str(scora) + " Model 2: " + str(scorb), fn_index=0) log.score1=self.score1.text log.score2=self.score2.text self.stop() #from ccm.lib.actr import * class ProceduralPlayer(ACTR): goal=Buffer() goal.set('play rps') def play_rock(goal='play rps',choice='waiting:True'): choice.choose('rock') def play_paper(goal='play rps',choice='waiting:True'): choice.choose('paper') def play_scissors(goal='play rps',choice='waiting:True'): choice.choose('scissors')