فهرست منبع

inittial commit

jezvgg 7 ماه پیش
کامیت
5541041b86

BIN
GAME.pdf


BIN
__pycache__/playerConfig.cpython-310.pyc


+ 107 - 0
game.py

@@ -0,0 +1,107 @@
+import numpy as np
+
+import sys
+sys.path.append('./players')
+
+import playerConfig
+import players.playerVeryGood as player1dist
+import players.playerGood as player2dist
+
+class Game():
+ def __init__(self, player1, player2,total1=0,total2=0):
+  self.player_positions=[0]*2
+  self.players=[0]*2
+  self.totals=[0]*2
+  self.known_player_positions=[0]*2
+  for i in range(2):
+   self.player_positions[i]=np.random.randint(0,playerConfig.MAX_STATE,playerConfig.DIMENSION)
+   self.known_player_positions[i]=np.array([playerConfig.MAX_STATE]*playerConfig.DIMENSION)
+  self.players[0]=player1
+  self.players[1]=player2
+  self.totals[0]=total1
+  self.totals[1]=total2
+  self.step=0
+  return
+
+ def GenKnownPositions(self,actual_positions=[],previous_positions=[],step=0):
+  new_positions=actual_positions.copy()
+  if playerConfig.MAX_STATE//2-step>0:
+   new_positions+=np.random.randint(0,playerConfig.MAX_STATE//2-step,actual_positions.shape[0])
+  pp=previous_positions[new_positions>previous_positions].copy()
+  new_positions[new_positions>previous_positions]=pp
+  return new_positions
+
+ def GetScore(self,pos1,pos2):
+  s=(np.array(pos1-pos2)*playerConfig.Weights).sum()+(np.random.rand()-0.5)
+  if s>0:
+   return 0
+  else:
+   return 1
+
+
+ def Step(self,person=0):
+  steps=[0]*2
+  for i in range(2):
+   self.known_player_positions[i]=self.GenKnownPositions(actual_positions=self.player_positions[i],
+                                previous_positions=self.known_player_positions[i],
+                                step=self.step)
+  i=person
+
+  steps[i]=self.players[i].Step(step=self.step,
+                                 own_state=self.player_positions[i],
+                                 known_state_opponent=self.known_player_positions[(i+1)%2])
+  self.step+=1
+  if steps[i]==playerConfig.PASS:
+    self.totals[i]-=playerConfig.Prices[playerConfig.PASS]
+    self.totals[(i+1)%2]+=playerConfig.Prices[playerConfig.PASS]
+    return playerConfig.PASS
+
+  if steps[i]==playerConfig.ACT:
+     score=self.GetScore(self.player_positions[0],self.player_positions[1])
+     if score==i:
+      self.totals[i]+=playerConfig.Prices[playerConfig.ACT]
+      self.totals[(i+1)%2]-=playerConfig.Prices[playerConfig.ACT]
+     if score==(i+1)%2:
+      self.totals[i]-=playerConfig.Prices[playerConfig.ACT]
+      self.totals[(i+1)%2]+=playerConfig.Prices[playerConfig.ACT]
+     return playerConfig.ACT
+
+  if steps[i]==playerConfig.LOOK:
+    self.totals[i]-=playerConfig.Prices[playerConfig.PASS]
+    self.totals[(i+1)%2]+=playerConfig.Prices[playerConfig.PASS]
+    return playerConfig.LOOK
+
+
+
+
+total1=0
+total2=0
+
+ITTS=30000
+for itt in range(ITTS):
+# print("Game",itt)
+ for person in range(2):
+  player1=player1dist.Player()
+  player2=player2dist.Player()
+  game=Game(player1,player2,total1,total2)
+#  print('actual:',game.player_positions)
+
+  cycle=0
+  person_act=person
+  while True and cycle<10:
+   result=game.Step(person=person_act)
+#   print('person:',person_act,'result:',result)
+#   print(np.array(game.totals)/itt)
+   print(person_act,'result:',playerConfig.Actions[result])
+   if result==playerConfig.ACT or result==playerConfig.PASS:
+    break
+   cycle+=1
+   person_act+=1
+   person_act%=2
+
+  total1=game.totals[0]
+  total2=game.totals[1]
+
+# 1 - GoodPlayer
+# 2 - BadPlayer
+print(np.array(game.totals)/ITTS)

+ 20 - 0
playerConfig.py

@@ -0,0 +1,20 @@
+import numpy as np
+
+DIMENSION=4
+MAX_STATE=10
+
+PASS=0
+ACT=1
+LOOK=2
+
+Actions=[0]*3
+Actions[ACT]='Act'
+Actions[PASS]='Pass'
+Actions[LOOK]='Look'
+
+Prices=[0]*3
+Prices[ACT]=10
+Prices[PASS]=3
+Prices[LOOK]=1
+
+Weights=np.array([3,2,1,1])

BIN
players/__pycache__/playerDummy.cpython-310.pyc


BIN
players/__pycache__/playerGood.cpython-310.pyc


BIN
players/__pycache__/playerVeryGood.cpython-310.pyc


+ 10 - 0
players/playerDummy.py

@@ -0,0 +1,10 @@
+import numpy as np
+import playerConfig
+
+
+class Player():
+ def __init__(self):
+  return
+
+ def Step(self,step=0,own_state=[],known_state_opponent=[]):
+  return np.random.randint(0,3)

+ 16 - 0
players/playerGood.py

@@ -0,0 +1,16 @@
+import numpy as np
+import playerConfig
+
+
+class Player():
+ def __init__(self):
+  return
+
+ def Step(self,step=0,own_state=[],known_state_opponent=[]):
+  score=((np.array(own_state)-np.array(known_state_opponent))*playerConfig.Weights).sum()
+  if score>0:
+   return playerConfig.ACT
+  if score<0:
+   return playerConfig.PASS
+  return playerConfig.LOOK
+

+ 39 - 0
players/playerVeryGood.py

@@ -0,0 +1,39 @@
+import numpy as np
+import playerConfig
+
+
+class Player():
+    def __init__(self):
+        return
+
+    def Step(self,step=0,own_state=[],known_state_opponent=[]):
+        chaos = 5-step
+
+        if chaos <= 0:
+            score=((np.array(own_state)-np.array(known_state_opponent))*playerConfig.Weights).sum()
+            if score>0:
+                return playerConfig.ACT
+            return playerConfig.PASS
+
+
+        our_first_card = range(known_state_opponent[0]-chaos if known_state_opponent[0]-chaos > 0 else 0, known_state_opponent[0]+1)
+        our_second_card = range(known_state_opponent[1]-chaos if known_state_opponent[1]-chaos > 0 else 0, known_state_opponent[1]+1)
+        our_third_card = range(known_state_opponent[2]-chaos if known_state_opponent[2]-chaos > 0 else 0, known_state_opponent[2]+1)
+        our_fourth_card = range(known_state_opponent[3]-chaos if known_state_opponent[3]-chaos > 0 else 0, known_state_opponent[3]+1)
+        print(our_first_card, our_second_card, our_fourth_card, our_third_card)
+        our_results = []
+        for first in our_first_card:
+            for second in our_second_card:
+                for third in our_third_card:
+                    for fourth in our_fourth_card:
+                        our_results.append(((np.array(own_state)-np.array([first, second, third, fourth]))*playerConfig.Weights).sum() > 0)
+        our_prob = (our_results.count(True) / len(our_results))*100
+
+        if our_prob > 70:
+            return playerConfig.ACT
+        if our_prob < 31:
+            return playerConfig.PASS
+        return playerConfig.LOOK
+        
+    
+