Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- game = [
- [1, 2, 1],
- [2, 0, 1],
- [1, 0, 2]
- ]
- def boardgame(game, run=0):
- def checklogic(game):
- win = True
- for pos, row in enumerate(game):
- firstcol = row[0]
- if row.count(0) >= 1:
- for col in row:
- if col != firstcol:
- win = False
- else:
- win = 'Next'
- break
- win = True
- for col in row:
- if col != firstcol:
- win = False
- break
- if win == True:
- if firstcol == 1:
- print("player 1 won")
- break
- elif firstcol == 2:
- print("player 2 won")
- break
- elif firstcol == 0:
- win = 'Next'
- break
- return win
- tmp_col = []
- if run == 0:
- result = checklogic(game)
- if result is False:
- boardgame(game, 1)
- elif result == 'Next':
- boardgame(game, 4)
- elif run == 1:
- for pos, row in enumerate(game):
- tmp_data = []
- for p, v in enumerate(row):
- tmp_data.append(game[p][pos])
- tmp_col.append(tmp_data)
- result = checklogic(tmp_col)
- if result is False:
- boardgame(game, 2)
- elif result == 'Next':
- boardgame(game, 4)
- elif run == 2:
- for pos, row in enumerate(game):
- tmp_data = []
- tmp_pos = pos
- tmp_pos_max = len(row)-1
- for p, v in enumerate(row):
- tmp_data.append(game[p][tmp_pos])
- tmp_pos += 1
- if tmp_pos > len(row)-1:
- tmp_pos = len(row)-1
- tmp_col.append(tmp_data)
- tmp_data = []
- for p, v in enumerate(row):
- tmp_data.append(game[p][tmp_pos_max])
- tmp_pos_max -= 1
- if tmp_pos_max < 0:
- tmp_pos_max = 0
- tmp_col.append(tmp_data)
- result = checklogic(tmp_col)
- if result is False:
- boardgame(game, 3)
- elif result == 'Next':
- boardgame(game, 4)
- elif run == 3:
- print('draw game')
- else:
- print('Next turn')
- boardgame(game)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement