Spaces:
Runtime error
Runtime error
Commit
·
3fe9033
1
Parent(s):
a58567b
Create dcogsphere.py
Browse files- dcogsphere.py +94 -0
dcogsphere.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from python_actr import *
|
| 2 |
+
log=log()
|
| 3 |
+
|
| 4 |
+
class RPSChoice(Model):
|
| 5 |
+
choice=None
|
| 6 |
+
font='Arial 20'
|
| 7 |
+
waiting=True
|
| 8 |
+
|
| 9 |
+
def start(self):
|
| 10 |
+
self.visible=True
|
| 11 |
+
self.text=self.instructions
|
| 12 |
+
|
| 13 |
+
def choose(self,option):
|
| 14 |
+
if not self.waiting: return
|
| 15 |
+
if option not in ['rock','paper','scissors']: return
|
| 16 |
+
self.choice=option
|
| 17 |
+
self.visible=False
|
| 18 |
+
self.waiting=False
|
| 19 |
+
|
| 20 |
+
# check to see if both players have made a choice
|
| 21 |
+
if self.parent.choice1.choice is not None and self.parent.choice2.choice is not None:
|
| 22 |
+
self.parent.determine_winner()
|
| 23 |
+
|
| 24 |
+
def reset(self):
|
| 25 |
+
self.text=self.instructions
|
| 26 |
+
self.waiting=True
|
| 27 |
+
self.visible=True
|
| 28 |
+
self.choice=None
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class RockPaperScissors(Model):
|
| 32 |
+
choice1=RPSChoice(x=0.5,y=0.2,instructions='Choose: Rock(1) Paper(2) Scissors(3)')
|
| 33 |
+
choice2=RPSChoice(x=0.5,y=0.8,instructions='Choose: Rock(Z) Paper(X) Scissors(C)')
|
| 34 |
+
|
| 35 |
+
result=Model(x=0.5,y=0.5,visible=False)
|
| 36 |
+
|
| 37 |
+
score1=Model(text=0,x=0.9,y=0.1)
|
| 38 |
+
score2=Model(text=0,x=0.9,y=0.9)
|
| 39 |
+
|
| 40 |
+
trials=0
|
| 41 |
+
|
| 42 |
+
def key_pressed(self,key):
|
| 43 |
+
if key=='1': self.choice1.choose('rock')
|
| 44 |
+
if key=='2': self.choice1.choose('paper')
|
| 45 |
+
if key=='3': self.choice1.choose('scissors')
|
| 46 |
+
|
| 47 |
+
if key=='z': self.choice2.choose('rock')
|
| 48 |
+
if key=='x': self.choice2.choose('paper')
|
| 49 |
+
if key=='c': self.choice2.choose('scissors')
|
| 50 |
+
|
| 51 |
+
def determine_winner(self):
|
| 52 |
+
self.choice1.text=self.choice1.choice
|
| 53 |
+
self.choice2.text=self.choice2.choice
|
| 54 |
+
self.choice1.visible=True
|
| 55 |
+
self.choice2.visible=True
|
| 56 |
+
|
| 57 |
+
c1=self.choice1.choice
|
| 58 |
+
c2=self.choice2.choice
|
| 59 |
+
if c1==c2:
|
| 60 |
+
self.result.text="Tie!"
|
| 61 |
+
elif (c1=='rock' and c2=='scissors') or (c1=='paper' and c2=='rock') or (c1=='scissors' and c2=='paper'):
|
| 62 |
+
self.result.text="Player 1 wins!"
|
| 63 |
+
self.score1.text+=1
|
| 64 |
+
else:
|
| 65 |
+
self.result.text="Player 2 wins!"
|
| 66 |
+
self.score2.text+=1
|
| 67 |
+
self.result.visible=True
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
yield 1
|
| 71 |
+
|
| 72 |
+
self.result.visible=False
|
| 73 |
+
|
| 74 |
+
self.choice1.reset()
|
| 75 |
+
self.choice2.reset()
|
| 76 |
+
|
| 77 |
+
self.trials+=1
|
| 78 |
+
if self.trials>=100:
|
| 79 |
+
log.score1=self.score1.text
|
| 80 |
+
log.score2=self.score2.text
|
| 81 |
+
self.stop()
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
#from ccm.lib.actr import *
|
| 85 |
+
class ProceduralPlayer(ACTR):
|
| 86 |
+
goal=Buffer()
|
| 87 |
+
goal.set('play rps')
|
| 88 |
+
|
| 89 |
+
def play_rock(goal='play rps',choice='waiting:True'):
|
| 90 |
+
choice.choose('rock')
|
| 91 |
+
def play_paper(goal='play rps',choice='waiting:True'):
|
| 92 |
+
choice.choose('paper')
|
| 93 |
+
def play_scissors(goal='play rps',choice='waiting:True'):
|
| 94 |
+
choice.choose('scissors')
|