Skip to content

Commit d8bad61

Browse files
authored
Version 1.4.0 (#8)
* changing from a hard move limit to a limit of 40 moves without a capture * adding test instructions to readme * personalizing our mit license * formatting * version bump
1 parent fa8fb8d commit d8bad61

7 files changed

Lines changed: 45 additions & 29 deletions

File tree

‎LICENSE‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License
22

3-
Copyright (c) 2010-2018 Google, Inc. http://angularjs.org
3+
Copyright (c) 2010-2018 ImparaAI https://impara.ai
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

‎checkers/board.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def __init__(self):
1313
self.rows_per_user_with_pieces = 3
1414
self.position_layout = {}
1515
self.piece_requiring_further_capture_moves = None
16+
self.previous_move_was_capture = False
1617
self.searcher = BoardSearcher()
1718
BoardInitializer(self).initialize()
1819

@@ -44,6 +45,7 @@ def create_new_board_from_move(self, move):
4445
return new_board
4546

4647
def perform_capture_move(self, move):
48+
self.previous_move_was_capture = True
4749
piece = self.searcher.get_piece_by_position(move[0])
4850
originally_was_king = piece.king
4951
enemy_piece = piece.capture_move_enemies[move[1]]
@@ -58,6 +60,7 @@ def perform_capture_move(self, move):
5860
self.switch_turn()
5961

6062
def perform_positional_move(self, move):
63+
self.previous_move_was_capture = False
6164
self.move_piece(move)
6265
self.switch_turn()
6366

‎checkers/game.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@ class Game:
55
def __init__(self):
66
self.board = Board()
77
self.moves = []
8-
self.move_limit = 50
8+
self.consecutive_noncapture_move_limit = 40
9+
self.moves_since_last_capture = 0
910

1011
def move(self, move):
1112
if move not in self.get_possible_moves():
1213
raise ValueError('The provided move is not possible')
1314

1415
self.board = self.board.create_new_board_from_move(move)
1516
self.moves.append(move)
17+
self.moves_since_last_capture = 0 if self.board.previous_move_was_capture else self.moves_since_last_capture + 1
1618

1719
return self
1820

1921
def move_limit_reached(self):
20-
return len(self.moves) >= self.move_limit
22+
return self.moves_since_last_capture >= self.consecutive_noncapture_move_limit
2123

2224
def is_over(self):
2325
return self.move_limit_reached() or not self.get_possible_moves()

‎readme.md‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
A Python3 library that you can use to play a game of checkers/draughts. This is just a set of classes that you can use in your code, it's not an interactive shell checkersgame.
22

3-
- **Version:** 1.3.0
3+
- **Version:** 1.4.0
44

55
[![Build Status](https://travis-ci.org/ImparaAI/checkers.png?branch=master)](https://travis-ci.org/ImparaAI/checkers)
66

@@ -58,11 +58,10 @@ Review the move history:
5858
game.moves #[[int, int], [int, int], ...]
5959
```
6060

61-
Set a move limit and see if it's overrun:
61+
Change the consecutive noncapture move limit (default `40` according to the [rules](http://www.usacheckers.com/rulesofcheckers.php)):
6262

6363
```python
64-
game = Game()
65-
game.move_limit = 100
64+
game.consecutive_noncapture_move_limit = 20
6665
game.move_limit_reached() #True or False
6766
```
6867

@@ -77,4 +76,8 @@ for piece in game.board.pieces:
7776
piece.position #1-32
7877
piece.get_possible_capture_moves() #[[int, int], [int, int], ...]
7978
piece.get_possible_positional_moves() #[[int, int], [int, int], ...]
80-
```
79+
```
80+
81+
# Testing
82+
83+
Run `python3 -m unittest discover` from the root.

‎setup.py‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
long_description = fh.read()
55

66
setuptools.setup(
7-
name="imparaai-checkers",
8-
version="1.3.0",
9-
license='MIT',
10-
author="ImparaAI",
11-
author_email="author@example.com",
12-
description="Library for playing a standard game of checkers/draughts",
13-
long_description=long_description,
14-
long_description_content_type="text/markdown",
15-
url="https://github.com/ImparaAI/checkers",
16-
packages=setuptools.find_packages(),
17-
classifiers=[
7+
name = "imparaai-checkers",
8+
version = "1.4.0",
9+
license = 'MIT',
10+
author = "ImparaAI",
11+
author_email = "author@example.com",
12+
description = "Library for playing a standard game of checkers/draughts",
13+
long_description = long_description,
14+
long_description_content_type = "text/markdown",
15+
url = "https://github.com/ImparaAI/checkers",
16+
packages = setuptools.find_packages(),
17+
classifiers = [
1818
"Programming Language :: Python :: 3",
1919
"License :: OSI Approved :: MIT License",
2020
"Operating System :: OS Independent",

‎test/test_game_over.py‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,31 @@ def test_new_game_not_over(self):
1212
self.expect(False)
1313

1414
def test_win_by_capture(self):
15-
self.make_non_winning_moves([[10, 14], [23, 18], [14, 23], [26, 19], [11, 15], [19, 10], [6, 15], [22, 18], [15, 22], [25, 18], [9, 13], [21, 17], [13, 22],
15+
self.make_non_final_moves([[10, 14], [23, 18], [14, 23], [26, 19], [11, 15], [19, 10], [6, 15], [22, 18], [15, 22], [25, 18], [9, 13], [21, 17], [13, 22],
1616
[31, 26], [22, 31], [24, 19], [31, 24], [24, 15], [15, 22], [29, 25], [22, 29], [30, 25], [29, 22], [28, 24], [12, 16], [32, 27], [16, 20], [27, 23],
1717
[20, 27], [23, 18]])
1818

1919
self.move([22, 15]).expect(True)
2020

2121
def test_win_by_no_legal_moves(self):
22-
self.make_non_winning_moves([[11, 15], [22, 18], [15, 22], [25, 18], [12, 16], [18, 14], [9, 18], [23, 14], [10, 17], [21, 14], [5, 9], [14, 5], [6, 9],
22+
self.make_non_final_moves([[11, 15], [22, 18], [15, 22], [25, 18], [12, 16], [18, 14], [9, 18], [23, 14], [10, 17], [21, 14], [5, 9], [14, 5], [6, 9],
2323
[29, 25], [9, 13], [25, 22], [2, 6], [22, 18], [13, 17], [27, 23], [17, 21], [24, 19], [8, 12], [30, 25], [21, 30], [28, 24], [4, 8], [18, 14], [6, 10],
2424
[32, 27], [10, 17], [23, 18], [16, 23], [23, 32], [24, 19], [30, 23], [23, 14], [31, 27], [32, 23]])
2525

2626
self.move([23, 16]).expect(True)
2727

2828
def test_move_limit_draw(self):
29-
self.game.move_limit = 15
30-
self.make_non_winning_moves([[9, 13], [22, 17], [13, 22], [26, 17], [10, 14], [17, 10], [7, 14], [23, 18], [14, 23], [27, 18], [12, 16], [18, 15], [11, 18],
31-
[25, 22]])
29+
self.make_non_final_moves([[10, 14], [22, 17], [9, 13], [17, 10], [7, 14], [25, 22], [6, 10], [29, 25], [1, 6], [22, 18], [6, 9], [24, 19], [2, 6], [28, 24],
30+
[11, 16], [24, 20], [8, 11], [32, 28], [4, 8], [27, 24], [3, 7], [31, 27], [13, 17], [25, 22], [9, 13], [18, 9], [9, 2], [10, 14], [22, 18], [5, 9], [19, 15],
31+
[16, 19], [23, 16], [12, 19], [30, 25], [14, 23], [23, 32], [21, 14], [14, 5], [11, 18], [2, 11], [11, 4], [19, 23], [26, 19], [13, 17], [25, 21], [17, 22],
32+
[21, 17], [22, 25], [17, 14], [18, 22], [5, 1], [22, 26], [4, 8], [26, 31], [19, 15], [25, 30], [8, 11], [31, 26], [1, 6], [26, 23], [24, 19], [23, 16],
33+
[16, 7], [14, 10], [7, 14], [15, 10], [14, 7], [28, 24], [32, 28], [20, 16], [28, 19], [19, 12], [6, 9], [7, 10], [9, 13], [10, 7], [13, 9], [7, 3], [9, 6],
34+
[3, 7], [6, 1], [7, 11], [1, 6], [11, 8], [6, 9], [8, 11], [9, 6], [11, 8], [6, 9], [8, 11], [9, 6], [11, 8], [6, 9], [8, 11], [9, 6], [11, 8], [6, 9], [8, 11],
35+
[9, 6], [11, 8], [6, 9], [8, 11], [9, 6], [11, 8], [6, 9], [8, 11], [9, 6], [11, 8], [6, 9], [8, 11], [9, 6]])
3236

33-
self.move([18, 25]).expect(True)
37+
self.move([11, 8]).expect(True)
3438

35-
def make_non_winning_moves(self, moves):
39+
def make_non_final_moves(self, moves):
3640
for move in moves:
3741
self.move(move).expect(False)
3842

‎test/test_winner.py‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,13 @@ def test_win_by_no_legal_moves(self):
2929
self.move([23, 16]).expect(1)
3030

3131
def test_draw(self):
32-
self.game.move_limit = 15
33-
self.make_non_winning_moves([[9, 13], [22, 17], [13, 22], [26, 17], [10, 14], [17, 10], [7, 14], [23, 18], [14, 23], [27, 18], [12, 16], [18, 15], [11, 18],
34-
[25, 22], [18, 25]])
32+
self.make_non_winning_moves([[10, 14], [22, 17], [9, 13], [17, 10], [7, 14], [25, 22], [6, 10], [29, 25], [1, 6], [22, 18], [6, 9], [24, 19], [2, 6], [28, 24],
33+
[11, 16], [24, 20], [8, 11], [32, 28], [4, 8], [27, 24], [3, 7], [31, 27], [13, 17], [25, 22], [9, 13], [18, 9], [9, 2], [10, 14], [22, 18], [5, 9], [19, 15],
34+
[16, 19], [23, 16], [12, 19], [30, 25], [14, 23], [23, 32], [21, 14], [14, 5], [11, 18], [2, 11], [11, 4], [19, 23], [26, 19], [13, 17], [25, 21], [17, 22],
35+
[21, 17], [22, 25], [17, 14], [18, 22], [5, 1], [22, 26], [4, 8], [26, 31], [19, 15], [25, 30], [8, 11], [31, 26], [1, 6], [26, 23], [24, 19], [23, 16],
36+
[16, 7], [14, 10], [7, 14], [15, 10], [14, 7], [28, 24], [32, 28], [20, 16], [28, 19], [19, 12], [6, 9], [7, 10], [9, 13], [10, 7], [13, 9], [7, 3], [9, 6],
37+
[3, 7], [6, 1], [7, 11], [1, 6], [11, 8], [6, 9], [8, 11], [9, 6], [11, 8], [6, 9], [8, 11], [9, 6], [11, 8], [6, 9], [8, 11], [9, 6], [11, 8], [6, 9], [8, 11],
38+
[9, 6], [11, 8], [6, 9], [8, 11], [9, 6], [11, 8], [6, 9], [8, 11], [9, 6], [11, 8], [6, 9], [8, 11], [9, 6], [11, 8]])
3539

3640
def make_non_winning_moves(self, moves):
3741
for move in moves:

0 commit comments

Comments
 (0)