def color_display(goban): """Affiche dans le terminal le goban""" # Affichage des lettres des colonnes cprint(' ', bg="brown", end='') for i in range(len(goban.cell[0])): cprint(chr(65 + i) + ' ', bg="brown", end='') print('') # Première ligne de verticaux cprint(' ', bg="brown", end='') for i in goban.cell[0]: cprint(VR_LINE + ' ', bg="brown", end='') print('') nb_ligne = 1 # Pour chaque ligne for ligne in goban.cell: # Affichages des numéros de ligne cprint(repr(nb_ligne).rjust(2), bg="brown", end='') nb_ligne += 1 # Lignes horizontales cprint(HR_LINE * 2, bg="brown", end='') # Affichage des intersections for colonne in ligne: # Intersection if colonne == None: cprint(INTERSE + HR_LINE * 2, bg="brown", end='') # Pion else: # Le joueur blanc if colonne == 1: cprint("0", bg="brown", end='') cprint(HR_LINE * 2, fg="white", bg="brown", end='') # Le joueur noir else: cprint("0", fg="black", bg="brown", end='') cprint(HR_LINE * 2, fg="white", bg="brown", end='') print("") cprint(' ', bg="brown", end='') # Lignes verticales for colonne in ligne: cprint(VR_LINE + ' ', bg="brown", end='') print('')
def round_display(partie): # On affiche le numéro du tour cprint("\n\n\n - Tour numéro", str(partie.tour + 1), "-", fg="blue") cprint("----------------------------------", fg="blue") # Score du joueur noir cprint(" Joueur noir: " + str(partie.player1.score), fg="black", bg="blue", end="") # Score du joueur blanc cprint(" Joueur blanc: " + str(partie.player2.score) + " ", fg="white", bg="blue", end="") cprint("\n----------------------------------\n", fg="blue") # Affichage du goban color_display(partie.goban) print() # Affichage de la ligne d'input cprint(" Au tour du joueur ", bg="blue", end="") # Tour du joueur noir if partie.tour % 2 == 0: cprint("noir ", fg="black", bg="blue", end="") # Tour du joueur blanc else: cprint("blanc ", fg="white", bg="blue", end="") cprint(">> ", fg="white", bg="blue", end="") sys.stdout.flush()
def display_end_game(partie): print("\n\n") cprint(" ---------------------------------- ", fg="blue") cprint("| ", fg="black", end="|\n") cprint("|", fg="black", end="") cprint(" FIN DE PARTIE ", fg="blue", end="") cprint("|", fg="white", end="\n") cprint("| ", fg="black", end="|\n") # Score du joueur noir cprint("| Joueur noir: " + str(partie.player1.score), fg="black", bg="blue", end="") # Score du joueur blanc cprint(" Joueur blanc: " + str(partie.player2.score) + " |", fg="white", bg="blue", end="\n") cprint("| ", fg="black", end="|\n") cprint("| ", fg="black", end="|\n") # Territoire du joueur noir cprint("| Terr. noir: " + str(len(partie.player1.territory)) + " ", fg="black", bg="blue", end="") # Territoire du joueur blanc cprint(" Terr. blanc: " + str(len(partie.player2.territory)) + " |", fg="white", bg="blue", end="\n") cprint("| ", fg="black", end="|\n") cprint("| ", fg="black", end="|\n") # Territoire du joueur noir cprint("| Score noir: " + str(len(partie.player1.territory) + partie.player1.score) + " ", fg="black", bg="blue", end="") # Territoire du joueur blanc cprint(" Score blanc: " + str(len(partie.player2.territory) + partie.player2.score) + " |", fg="white", bg="blue", end="\n") cprint("| ", fg="black", end="|\n") cprint("|", fg="black", end="") if (len(partie.player1.territory) + partie.player1.score < len(partie.player2.territory) + partie.player2.score): cprint(" VICTOIRE JOUEUR BLANC ", fg="blue", end="") elif (len(partie.player1.territory) + partie.player1.score > len(partie.player2.territory) + partie.player2.score): cprint(" VICTOIRE JOUEUR NOIR ", fg="blue", end="") else: cprint(" EGALITE ", fg="blue", end="") cprint("|", fg="white", end="\n") cprint("| ", fg="black", end="|\n") cprint("| ", fg="black", end="|\n") cprint("| ", fg="black", end="|\n") cprint(" ---------------------------------- ", fg="blue")
def game_loop(game): global args global options player_passed = False while True: valid = False # Si c'est le tour du joueur 1 if game.tour % 2 == 0: current_id = 0 current_player = game.player1 # Si c'est le tour du joueur 2 else: current_id = 1 current_player = game.player2 # On recompte les scores game.player1.update_score() game.player2.update_score() # Affichage du goban if options.quiet_mode == True: pass elif options.minim == True: round_display_min(game) else: round_display(game) # Entrée des coordonnées coord = current_player.choose_move() # On parse l'entrée if current_player.isHuman == True: ret = parse_coord(coord) else: ret = coord # S'il faut quitter if ret == True: print() sys.exit(0) # Si l'entree est incorrecte elif ret == False: cprint("Erreur: entrée incorrecte", fg="red") # Si le joueur passe elif ret == "pass": # Si le joueur précédent a passé if player_passed == True: #TODO Affichage de fin de partie end_game(game) print() sys.exit(0) else: player_passed = True valid = True else: player_passed = False try: (col, lgn) = ret # Si le coup est possible ret = game.goban.test_move(col, lgn, current_player) # S'il y a capture if not ret == False: game.goban.cell = make_capture(game.goban.cell, ret) for group in ret: current_player.captures += len(group) # On pose le pion game.goban.make_move(col, lgn, current_id) # On enregistre la configuration actuelle tmp_goban = [] for old_lines in game.goban.cell: tmp_goban.append(list(old_lines)) game.goban.save_goban(tmp_goban) # On enregistre le coup du joueur current_player.save_move(lgn, col) valid = True except Forbidden_move as e: cprint("Erreur: coup interdit,", str(e), fg="red") valid = False if options.test_mode == True: sys.exit(1) # Si c'est valide if valid == True: # On passe au tour suivant game.tour += 1
def round_display(partie): # On affiche le numéro du tour cprint("\n\n\n - Tour numéro", str(partie.tour + 1), "-", fg = "blue") cprint("----------------------------------", fg = "blue") # Score du joueur noir cprint(" Joueur noir: " + str(partie.player1.score), fg = "black", bg = "blue", end = "") # Score du joueur blanc cprint(" Joueur blanc: " + str(partie.player2.score) + " ", fg = "white", bg = "blue", end = "") cprint("\n----------------------------------\n", fg = "blue") # Affichage du goban color_display(partie.goban) print() # Affichage de la ligne d'input cprint(" Au tour du joueur ", bg = "blue", end = "") # Tour du joueur noir if partie.tour % 2 == 0: cprint("noir ", fg = "black", bg = "blue", end = "") # Tour du joueur blanc else: cprint("blanc ", fg = "white", bg = "blue", end = "") cprint(">> ", fg = "white", bg = "blue", end = "") sys.stdout.flush()
def color_display(goban): """Affiche dans le terminal le goban""" # Affichage des lettres des colonnes cprint(' ', bg = "brown", end = '') for i in range(len(goban.cell[0])): cprint(chr(65 + i) + ' ', bg = "brown", end = '') print('') # Première ligne de verticaux cprint(' ', bg = "brown", end = '') for i in goban.cell[0]: cprint(VR_LINE + ' ', bg = "brown", end = '') print('') nb_ligne = 1 # Pour chaque ligne for ligne in goban.cell: # Affichages des numéros de ligne cprint(repr(nb_ligne).rjust(2), bg = "brown", end = '') nb_ligne += 1 # Lignes horizontales cprint(HR_LINE * 2, bg = "brown", end = '') # Affichage des intersections for colonne in ligne: # Intersection if colonne == None: cprint(INTERSE + HR_LINE * 2, bg = "brown", end = '') # Pion else: # Le joueur blanc if colonne == 1: cprint("0", bg = "brown", end = '') cprint(HR_LINE * 2, fg = "white", bg = "brown", end = '') # Le joueur noir else: cprint("0", fg = "black", bg = "brown", end = '') cprint(HR_LINE * 2, fg = "white", bg = "brown", end = '') print("") cprint(' ', bg = "brown", end = '') # Lignes verticales for colonne in ligne: cprint(VR_LINE + ' ', bg = "brown", end = '') print('')
def display_end_game(partie): print("\n\n") cprint(" ---------------------------------- ", fg = "blue") cprint("| ", fg = "black", end = "|\n") cprint("|", fg = "black", end = "") cprint(" FIN DE PARTIE ", fg = "blue", end = "") cprint("|", fg = "white", end = "\n") cprint("| ", fg = "black", end = "|\n") # Score du joueur noir cprint("| Joueur noir: " + str(partie.player1.score), fg = "black", bg = "blue", end = "") # Score du joueur blanc cprint(" Joueur blanc: " + str(partie.player2.score) + " |", fg = "white", bg = "blue", end = "\n") cprint("| ", fg = "black", end = "|\n") cprint("| ", fg = "black", end = "|\n") # Territoire du joueur noir cprint("| Terr. noir: " + str(len(partie.player1.territory)) + " ", fg = "black", bg = "blue", end = "") # Territoire du joueur blanc cprint(" Terr. blanc: " + str(len(partie.player2.territory)) + " |", fg = "white", bg = "blue", end = "\n") cprint("| ", fg = "black", end = "|\n") cprint("| ", fg = "black", end = "|\n") # Territoire du joueur noir cprint("| Score noir: " + str(len(partie.player1.territory) + partie.player1.score) + " ", fg = "black", bg = "blue", end = "") # Territoire du joueur blanc cprint(" Score blanc: " + str(len(partie.player2.territory) + partie.player2.score) + " |", fg = "white", bg = "blue", end = "\n") cprint("| ", fg = "black", end = "|\n") cprint("|", fg = "black", end = "") if (len(partie.player1.territory) + partie.player1.score < len(partie.player2.territory) + partie.player2.score): cprint(" VICTOIRE JOUEUR BLANC ", fg = "blue", end = "") elif (len(partie.player1.territory) + partie.player1.score > len(partie.player2.territory) + partie.player2.score): cprint(" VICTOIRE JOUEUR NOIR ", fg = "blue", end = "") else: cprint(" EGALITE ", fg = "blue", end = "") cprint("|", fg = "white", end = "\n") cprint("| ", fg = "black", end = "|\n") cprint("| ", fg = "black", end = "|\n") cprint("| ", fg = "black", end = "|\n") cprint(" ---------------------------------- ", fg = "blue")
def game_loop(game): global args global options player_passed = False while True: valid = False # Si c'est le tour du joueur 1 if game.tour % 2 == 0: current_id = 0 current_player = game.player1 # Si c'est le tour du joueur 2 else: current_id = 1 current_player = game.player2 # On recompte les scores game.player1.update_score() game.player2.update_score() # Affichage du goban if options.quiet_mode == True: pass elif options.minim == True: round_display_min(game) else: round_display(game) # Entrée des coordonnées coord = current_player.choose_move() # On parse l'entrée if current_player.isHuman == True: ret = parse_coord(coord) else: ret = coord # S'il faut quitter if ret == True: print() sys.exit(0) # Si l'entree est incorrecte elif ret == False: cprint("Erreur: entrée incorrecte", fg = "red") # Si le joueur passe elif ret == "pass": # Si le joueur précédent a passé if player_passed == True: #TODO Affichage de fin de partie end_game(game) print() sys.exit(0) else: player_passed = True valid = True else: player_passed = False try: (col, lgn) = ret # Si le coup est possible ret = game.goban.test_move(col, lgn, current_player) # S'il y a capture if not ret == False: game.goban.cell = make_capture(game.goban.cell, ret) for group in ret: current_player.captures += len(group) # On pose le pion game.goban.make_move(col, lgn, current_id) # On enregistre la configuration actuelle tmp_goban = [] for old_lines in game.goban.cell: tmp_goban.append(list(old_lines)) game.goban.save_goban(tmp_goban) # On enregistre le coup du joueur current_player.save_move(lgn, col) valid = True except Forbidden_move as e: cprint("Erreur: coup interdit,", str(e), fg = "red") valid = False if options.test_mode == True: sys.exit(1) # Si c'est valide if valid == True: # On passe au tour suivant game.tour += 1