-
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.
Added proper unittest; bumped version
- Loading branch information
Showing
9 changed files
with
202 additions
and
63 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
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
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,44 @@ | ||
# | ||
# Game of Thai 21 example | ||
# | ||
# Description: Twenty one flags are placed on a beach. Each player takes a turn | ||
# removing between 1 and 3 flags. The player that removes the last remaining flag wins. | ||
# | ||
# This game was introduced by an episode of Survivor: http://survivor-org.wikia.com/wiki/21_Flags | ||
# | ||
|
||
import strutils | ||
import turn_based_game | ||
import tables | ||
|
||
type | ||
GameOfThai21* = ref object of Game | ||
pile*: int | ||
|
||
method setup*(self: GameOfThai21, players: seq[Player]) = | ||
self.default_setup(players) | ||
self.pile = 21 | ||
|
||
method set_possible_moves*(self: GameOfThai21, moves: var OrderedTable[string, string]) = | ||
if self.pile==1: | ||
moves = {"1": "Take One"}.toOrderedTable | ||
elif self.pile==2: | ||
moves = {"1": "Take One", "2": "Take Two"}.toOrderedTable | ||
else: | ||
moves = {"1": "Take One", "2": "Take Two", "3": "Take Three"}.toOrderedTable | ||
|
||
method make_move*(self: GameOfThai21, move: string): string = | ||
var count = move.parseInt() | ||
self.pile -= count # remove bones. | ||
return "$# flags removed.".format([count]) | ||
|
||
method determine_winner*(self: GameOfThai21) = | ||
if self.winner_player_number > 0: | ||
return | ||
if self.pile <= 0: | ||
self.winner_player_number = self.current_player_number | ||
|
||
# the following method is not _required_, but makes it nicer to read | ||
method status*(self: GameOfThai21): string = | ||
"$# flags available.".format([self.pile]) | ||
|
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 @@ | ||
--path:"../src/" |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.