Advertisement
katkid

board game

May 29th, 2019
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.45 KB | None | 0 0
  1.  
  2. game = [
  3.     [1, 2, 1],
  4.     [2, 0, 1],
  5.     [1, 0, 2]
  6. ]
  7.  
  8. def boardgame(game, run=0):
  9.     def checklogic(game):
  10.         win = True
  11.  
  12.         for pos, row in enumerate(game):
  13.             firstcol = row[0]
  14.  
  15.             if row.count(0) >= 1:
  16.                 for col in row:
  17.                     if col != firstcol:
  18.                         win = False
  19.                     else:
  20.                         win = 'Next'
  21.                 break
  22.  
  23.  
  24.  
  25.             win = True
  26.             for col in row:
  27.                 if col != firstcol:
  28.                     win = False
  29.                     break
  30.  
  31.             if win == True:
  32.                 if firstcol == 1:
  33.                     print("player 1 won")
  34.                     break
  35.                 elif firstcol == 2:
  36.                     print("player 2 won")
  37.                     break
  38.                 elif firstcol == 0:
  39.                     win = 'Next'
  40.                     break
  41.  
  42.         return win
  43.  
  44.     tmp_col = []
  45.     if run == 0:
  46.         result = checklogic(game)
  47.  
  48.         if result is False:
  49.             boardgame(game, 1)
  50.         elif result == 'Next':
  51.             boardgame(game, 4)
  52.  
  53.     elif run == 1:
  54.         for pos, row in enumerate(game):
  55.             tmp_data = []
  56.             for p, v in enumerate(row):
  57.                 tmp_data.append(game[p][pos])
  58.             tmp_col.append(tmp_data)
  59.  
  60.         result = checklogic(tmp_col)
  61.  
  62.         if result is False:
  63.             boardgame(game, 2)
  64.         elif result == 'Next':
  65.             boardgame(game, 4)
  66.  
  67.     elif run == 2:
  68.         for pos, row in enumerate(game):
  69.             tmp_data = []
  70.             tmp_pos = pos
  71.             tmp_pos_max = len(row)-1
  72.  
  73.             for p, v in enumerate(row):
  74.                 tmp_data.append(game[p][tmp_pos])
  75.  
  76.                 tmp_pos += 1
  77.                 if tmp_pos > len(row)-1:
  78.                     tmp_pos = len(row)-1
  79.  
  80.             tmp_col.append(tmp_data)
  81.             tmp_data = []
  82.             for p, v in enumerate(row):
  83.                 tmp_data.append(game[p][tmp_pos_max])
  84.  
  85.                 tmp_pos_max -= 1
  86.                 if tmp_pos_max < 0:
  87.                     tmp_pos_max = 0
  88.  
  89.             tmp_col.append(tmp_data)
  90.  
  91.         result = checklogic(tmp_col)
  92.  
  93.         if result is False:
  94.             boardgame(game, 3)
  95.         elif result == 'Next':
  96.             boardgame(game, 4)
  97.     elif run == 3:
  98.         print('draw game')
  99.     else:
  100.         print('Next turn')
  101.  
  102.  
  103.  
  104.  
  105. boardgame(game)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement