-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplay_othello_console.py
55 lines (46 loc) · 1.54 KB
/
play_othello_console.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# This script was used for development purposes to test the Othello game logic
# in the console. Specifically, the script is designed to be used by an offline
# user to play Othello against a random agent.
import time
from src.game import Game
from src.player import Player, PlayerType
from src.board import SquareType
# Ask offline user to choose their color
print("Do you want to play as black or white?")
color = input("Enter: ").lower()
while color not in ['black', 'white']:
print("Do you want to play as black or white?")
color = input("Enter: ").lower()
if color == 'black':
player_black = Player(PlayerType.OFFLINE, SquareType.BLACK)
player_white = Player(PlayerType.RANDOM, SquareType.WHITE)
else:
player_black = Player(PlayerType.RANDOM, SquareType.BLACK)
player_white = Player(PlayerType.OFFLINE, SquareType.WHITE)
# Initialise game
game = Game(player_black, player_white)
while not game.is_finished:
print("\n\n")
game.board.display()
time.sleep(1.5)
if game.active == game.player_black:
if game.prev_move != None:
print("White has moved.")
time.sleep(1)
print("Black to move.")
else:
if game.prev_move != None:
print("Black has moved.")
time.sleep(1)
print("White to move.")
time.sleep(1)
game.get_player_move()
game.make_move()
game.change_turn()
game.update_valid_moves()
game.update_scores()
game.check_finished()
time.sleep(1.5)
# Display final game board
game.board.display()
print("Game over.")