-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
92 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,9 @@ Bug fix | |
|
||
## chessboard 1.1.0 | ||
Add color | ||
|
||
## chessboard 1.1.1 - 1.1.2 | ||
Bug fix | ||
|
||
## chessboard 1.2.0 | ||
Stable version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__version__ = '1.2.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,39 @@ | ||
import sys | ||
from chessboard import Chessboard | ||
from chessboard import Chessboard, PositionError | ||
from colorline import cprint | ||
|
||
def play_game(): | ||
from functools import partial | ||
|
||
eprint = partial(cprint, color='r', bcolor='c', mode='highlight') | ||
|
||
def main(): | ||
while True: | ||
game_name = input('Please input the game name: ') | ||
try: | ||
board = Chessboard(game_name=game_name) | ||
except ValueError as e: | ||
cprint(e) | ||
eprint(e) | ||
continue | ||
else: | ||
break | ||
|
||
board.print_pos() | ||
while True: | ||
player_number = board.get_player() | ||
cprint('Player {}\'s turn: '.format(player_number), color='y', bcolor='c', end='') | ||
ipt = input('') | ||
try: | ||
ipt = input('Input:') | ||
except: | ||
cprint('Input Error: try again.', color='g') | ||
pos = board.handle_input(ipt, check=True) | ||
except Exception as e: | ||
eprint(e) | ||
board.print_pos() | ||
continue | ||
if game_name != 'fourinarow': | ||
try: | ||
a = board.handle_input(ipt, check=True) | ||
except Exception as e: | ||
cprint(e, color='g') | ||
board.print_pos() | ||
continue | ||
else: | ||
a = board.handle_input(ipt, place=False) | ||
if a is None: | ||
board.print_pos() | ||
continue | ||
column_num = int(a[0]) | ||
current_col = [_[column_num - 1] for _ in board.pos] | ||
current_row = board.get_not_num(current_col) | ||
if current_row == 0: | ||
cprint('No place to put your chess!', color='g') | ||
continue | ||
else: | ||
try: | ||
a = board.set_pos(x=current_row, y=column_num, check=True) | ||
except (PositionError, Exception) as e: | ||
cprint(e, color='g') | ||
continue | ||
if a is True: | ||
cprint('player {} wins'.format(board.get_player()), color='y', bcolor='b') | ||
if pos is True: | ||
cprint('player {} wins'.format(player_number), color='y', bcolor='b') | ||
board.print_pos() | ||
sys.exit(0) | ||
board.print_pos(coordinates=a) | ||
board.print_pos(coordinates=pos) | ||
#print(str(board)) | ||
|
||
if __name__ == '__main__': | ||
play_game() | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters