1+ #!/usr/bin/env python3 
2+ 13import  os 
24import  configparser 
35import  itertools 
@@ -17,7 +19,6 @@ class UIGame(object):
1719 _idx_to_col  =  {0 : 'A' , 1 : 'B' , 2 : 'C' , 3 : 'D' , 4 : 'E' }
1820
1921 def  __init__ (self , canvas , statustext ):
20-  super (UIGame , self ).__init__ ()
2122 # self.board = Board('1GG1G/1GGGT/1GGGG/GGTGG/GTGTG t g0 c3 mA3') 
2223 self .board  =  Board ()
2324
@@ -28,22 +29,22 @@ def __init__(self, canvas, statustext):
2829 self .from_idx  =  None 
2930
3031 self .tiger_radius  =  7 
31-  self .sheep_radius  =  5 
32+  self .goat_radius  =  5 
3233
3334 self .board_grid_x  =  [10 , 60 , 110 , 160 , 210 ]
3435 self .board_grid_y  =  [10 , 60 , 110 , 160 , 210 ]
3536 self .board_rect  =  [1 , 1 , 221 , 221 ]
3637
3738 self .game  =  None 
3839 self .win  =  '' 
39-  self .ai_turn  =  False 
40+  self .ai_turn  =  True 
4041
41-  self .config  =  configparser .SafeConfigParser (defaults = {
42-  'sheepcolor ' : 'gray' ,
42+  self .config  =  configparser .ConfigParser (defaults = {
43+  'goatcolor ' : 'gray' ,
4344 'tigercolor' : 'yellow' 
4445 })
4546 self .config .add_section ('ui' )
46-  self .sheep_color  =  self .config .get ('ui' , 'sheepcolor ' )
47+  self .goat_color  =  self .config .get ('ui' , 'goatcolor ' )
4748 self .tiger_color  =  self .config .get ('ui' , 'tigercolor' )
4849
4950 self .draw_board ()
@@ -192,7 +193,7 @@ def draw(self):
192193 self .make_ai_move ()
193194
194195 tr  =  self .tiger_radius 
195-  sr  =  self .sheep_radius 
196+  sr  =  self .goat_radius 
196197
197198 # display the tigers and goats on the ui board 
198199 for  entry , (y , x ) in  zip (Board ._get_full_position (self .board .position .split ()[0 ]),
@@ -206,7 +207,7 @@ def draw(self):
206207 elif  entry  ==  "G" :
207208 self .cids .append (self .canvas .create_oval (x  -  sr , y  -  sr ,
208209 x  +  sr , y  +  sr ,
209-  fill = self .sheep_color ))
210+  fill = self .goat_color ))
210211
211212 def  check_win (self ):
212213 # read the current board position 
@@ -217,48 +218,48 @@ def check_win(self):
217218 self .win  =  'tigers' 
218219 return 
219220
220-  elif  self .board .winner  ==  Board .Player .T :
221+  elif  self .board .winner  ==  Board .Player .G :
221222 # self.game.wait() 
222223 # self.game = None 
223224 self .statustext .set ('Goats win!' )
224225 self .win  =  'goats' 
225226 return 
226227
227228 def  new (self ):
228-  #  self.config = configparser.SafeConfigParser ()
229-  #  self.config.read(os.path.expanduser('uiconf'))
230- 231-  #  if self.config.has_option('game', 'ai'):
232-  #  if self.config.get('game', 'ai').lower() == 'sheep ':
233-  #   cmdline.append('-s') 
234-  #   elif self.config.get('game', 'ai').lower() == 'tiger':
235-  #   cmdline.append('-t') 
236-  #  else:
237-  #   cmdline.append('-s') 
238- 239-  #  if self.config.has_option('game', 'aistrength'):
240-  #   cmdline.append( self.config.get('game', 'aistrength') )
241-  #  else:
242-  #   cmdline.append('3') 
229+  self .config  =  configparser .ConfigParser ()
230+  self .config .read (os .path .expanduser ('uiconf' ))
231+ 232+  if  self .config .has_option ('game' , 'ai' ):
233+  if  self .config .get ('game' , 'ai' ).lower () ==  'goat ' :
234+  self . ai_turn = True 
235+  elif  self .config .get ('game' , 'ai' ).lower () ==  'tiger' :
236+  self . ai_turn = False 
237+  else :
238+  pass 
239+ 240+  if  self .config .has_option ('game' , 'aistrength' ):
241+  aistrength = self .config .get ('game' , 'aistrength' )
242+  else :
243+  aistrength = 6 
243244
244245 # self.win = '' 
245-  self .init_ai ()
246+  self .init_ai (int ( aistrength ) )
246247 # self.engine.make_best_move() 
247248 # self.check_win() 
248249 self .draw ()
249250
250-  def  init_ai (self ):
251+  def  init_ai (self ,  aistrength ):
251252 self .ai_vs_ai  =  False 
252253 self .board  =  Board ()
253-  self .engine  =  Engine (self .board , depth = 5 )
254+  self .engine  =  Engine (self .board , depth = aistrength )
254255
255256 def  make_ai_move (self , ev = None ):
256257 move  =  self .engine .get_best_move ()
257258 self .apply_move (move )
258259
259260
260261def  configure ():
261-  config  =  configparser .SafeConfigParser ()
262+  config  =  configparser .ConfigParser ()
262263 config .add_section ('game' )
263264 config .read (os .path .expanduser ('uiconf' ))
264265
0 commit comments