Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 5 additions & 31 deletions othello/natymundo/othello.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Othello

import numpy as np


VIDE = 0
NOIR = 1
BLANC = -1
Expand All @@ -14,7 +17,6 @@ class Othello:
Le jeu du même nom
"""

<<<<<<< HEAD
def __init__(self, jeu=None):
self.log = 'LOG: \n'
if jeu:
Expand All @@ -23,23 +25,11 @@ def __init__(self, jeu=None):
self.jeu = np.zeros((SIZE, len(COLONNES)), dtype=np.int8)
self.jeu[3][4], self.jeu[4][3] = NOIR, NOIR
self.jeu[3][3], self.jeu[4][4] = BLANC, BLANC
=======
def __init__(self):
# évidemment la première remarque est qu'un tableau numpy
# serait bien plus efficace pour modéliser le jeu
self.jeu = []
for l in range(SIZE):
self.jeu.append([])
self.jeu[l] = [VIDE]*len(COLONNES)
self.jeu[3][4], self.jeu[4][3] = NOIR, NOIR
self.jeu[3][3], self.jeu[4][4] = BLANC, BLANC
>>>>>>> parent of 9f141df... Les petites modifications faciles
self.joueur = NOIR
self.brouillon = None
self.update() # une copie du jeu sur laquelle on écrit plein d'infos utiles

def __str__(self):
<<<<<<< HEAD
return '\n'.join(';'.join(str(i) for i in ligne) for ligne in self.jeu)

def write(self, file):
Expand All @@ -54,24 +44,11 @@ def read(self, file):
array.append(int(i))
jeu = np.array((array), dtype=np.int8)
return jeu.reshape((SIZE, len(COLONNES)))
=======
txt = ' ' + ' '.join(COLONNES) + '\n'
# pourquoi pas plus simplement
# for l, ligne in zip(LIGNES, self.jeu):
for l in range(SIZE):
txt += LIGNES[l] + '|'
for k in self.jeu[l]:
txt += ' ' + str(k)
txt += ' |' + LIGNES[l] + '\n'
txt += ' ' + ' '.join(COLONNES)
return txt
>>>>>>> parent of 9f141df... Les petites modifications faciles

def next(self):
self.joueur = -self.joueur

# je vous conseille de choisir des noms + parlants que 'adv'
def adv(self, couleur):
def adversaire(self, couleur):
return -couleur

def update(self):
Expand Down Expand Up @@ -135,7 +112,7 @@ def isJouable(self, ligne, colonne, couleur):
"""
pos = VIDE
if self.jeu[ligne][colonne] not in (NOIR, BLANC):
if self.adv(couleur) in self.casesAdjacentes(ligne, colonne, couleur):
if self.adversaire(couleur) in self.casesAdjacentes(ligne, colonne, couleur):
pos = self.retournera(ligne, colonne, couleur)
if not pos:
pos = VIDE
Expand Down Expand Up @@ -194,8 +171,5 @@ def playJoueur(self, ligne, colonne):
return self.toString((ligne, colonne))
else:
return False
<<<<<<< HEAD


=======
>>>>>>> parent of 9f141df... Les petites modifications faciles