Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # list - zwraca tablice z indeksami niezerowych elementów tab
- def non0(tab):
- r = []
- for i in range(len(tab)):
- if not tab[i] == 0: r.append(i)
- return r
- # bool - zwraca True gdy dana pozycja jest wygrywajaca i False gdy nie jest
- def winposition(tab):
- if len(non0(tab)) == 2 and non0(tab)[0] == non0(tab)[1]:
- return True
- else:
- return False
- # list - zwraca wszystkie możliwe ruchy dla danej gry
- def allmoves(tab):
- r = []
- for i in tab:
- for j in range(1, tab[i]+1):
- r.append([i, j])
- return r
- #TODO:
- # list - zwraca tablice bedaca stanem gry po wykonaniu danego ruchu
- def gamestate(move, tab):
- # bool - zwraca True gdy dana pozycja jest potencjalnie wygrywajaca dla przeciwnika
- def lossposition(tab):
- r = False
- for move in allmoves(tab):
- if winposition( gamestate(move, tab) ): r = True
- return r
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement