Commit 069b0a01 authored by DUFAIX Clement's avatar DUFAIX Clement
Browse files

mecanique de jeu finit

parent ce4911d2
......@@ -11,18 +11,39 @@ class Game:
# def __init__(self):
@staticmethod
def movePawn(positionToMove):
return not Game.emptyPlaceToMove(positionToMove)
positionToMove = positionToMove-1 # pour la position dans le tableau
newPosition = Game.emptyPlaceToMove(positionToMove)
if newPosition == -1: #si aucune place n'a été trouvé ou possible
return False
else : #on bouge le pion, son ancienne case est maintenant vide
Game.boardGame[newPosition] = Game.boardGame[positionToMove]
Game.boardGame[positionToMove] = 0
return True
@staticmethod
def emptyPlaceToMove(positionToMove): #-1 if impossible
if Game.boardGame[8] == 0:
if Game.boardGame[(positionToMove+1)%8] == Game.actualPlayer and Game.boardGame[(positionToMove-1)%8] == Game.actualPlayer: return False
return True
if not Game.boardGame[positionToMove] == Game.actualPlayer: return -1 #si on essaie de bouger autre chose que un de ses pions : False
if Game.boardGame[8] == 0: # si la place au milieu est libre
# seulement si un point adverse autours du joueur est présent
if (Game.boardGame[(positionToMove+1)%8] == Game.actualPlayer) and (Game.boardGame[(positionToMove-1)%8] == Game.actualPlayer): return -1
return 8
else :
if(positionToMove == 8) : # on bouge le pion du milieu, on cherche la case vide
for x in range(8):
if Game.boardGame[x] == 0:
return x
break
# sinon si il y a une position libre adjacente
if Game.boardGame[(positionToMove + 1) % 8] == 0: return (positionToMove + 1) % 8
if Game.boardGame[(positionToMove - 1) % 8] == 0: return (positionToMove - 1) % 8
return -1
if __name__ == "__main__":
print(Game.movePawn(0))
#print(Game.boardGame[(8 + 1) % 8] == Game.actualPlayer)
#print(8%8)
\ No newline at end of file
print(Game.movePawn(4))
print(Game.boardGame[(0 - 1) % 8] == Game.actualPlayer)
Game.actualPlayer = 2
print(Game.movePawn(5))
Game.actualPlayer = 1
print(Game.movePawn(9))
print(Game.boardGame)
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment