forked from pearstopher/chess
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_tui.py
More file actions
53 lines (42 loc) · 1.38 KB
/
Copy pathexample_tui.py
File metadata and controls
53 lines (42 loc) · 1.38 KB
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
# Chess Program
#
# This chess program currently responds to the user by making random moves.
#
# Basic requirements:
# > pip install python-chess
# > pip install pygame
#
import chess
from ChessHelpers import ChessEngineHelper
CHECKMATE = 1000
STALEMATE = 0
GUI = False # choose between graphical or terminal interface
if GUI:
from interface.gui import play_chess
else:
from interface.tui import play_chess
def main():
# Let's make the move generator play ten games against itself
# create an array to hold the game outcomes
outcomes = []
for _ in range(10):
# create a chess board object
board = chess.Board()
# run the game loop to display the board UI
# parameters:
# a chess board
# a move generation function for white (optional, defaults to player)
# a move generation function for black (optional, defaults to player)
#
# return value:
# the outcome of the game
move_generator = ChessEngineHelper.MoveGenerator()
outcome = play_chess(board, white=move_generator.random_move,
black=move_generator.greedy_best_next_move)
outcomes.append(outcome)
# display all the results
print("\n\nResults:")
for o in outcomes:
print(o)
if __name__ == '__main__':
main()