Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. # list - zwraca tablice z indeksami niezerowych elementów tab
  2. def non0(tab):
  3.     r = []
  4.     for i in range(len(tab)):
  5.         if not tab[i] == 0: r.append(i)
  6.     return r
  7.  
  8.  
  9. # bool - zwraca True gdy dana pozycja jest wygrywajaca i False gdy nie jest
  10. def winposition(tab):
  11.     if len(non0(tab)) == 2 and non0(tab)[0] == non0(tab)[1]:
  12.         return True
  13.     else:
  14.         return False
  15.  
  16.  
  17. # list - zwraca wszystkie możliwe ruchy dla danej gry
  18. def allmoves(tab):
  19.     r = []
  20.     for i in tab:
  21.         for j in range(1, tab[i]+1):
  22.             r.append([i, j])
  23.     return r
  24.  
  25. #TODO:
  26. # list - zwraca tablice bedaca stanem gry po wykonaniu danego ruchu
  27. def gamestate(move, tab):
  28.    
  29.  
  30. # bool - zwraca True gdy dana pozycja jest potencjalnie wygrywajaca dla przeciwnika
  31. def lossposition(tab):
  32.     r = False
  33.     for move in allmoves(tab):
  34.         if winposition( gamestate(move, tab) ): r = True  
  35.     return r
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement