This file contains hidden or 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
"""Moves a checker from starting point by a given number of steps"""
dest = start + steps
dest_range = range(0, 24)
self.points[start].remove_checker(player)
self.points[start][player] -= 1
if dest in dest_range:
self.points[dest].add_checker(player)
self.points[dest][player] += 1
if self.checkers_at_home(player) == 15:
self.allow_bear_off[player] = True
class Point:
"""A point is one of the 24 triangles on the board where
the players' checkers are placed."""
def __init__(self):
self.checkers = {'W':0, 'B':0}
def is_open_for(self, player):
def is_point_open(self, player, point):
"""A point is open for a player if the no. of opponent's
checkers already present on it is 0 or 1. A player can
move a checker to a point only if it is open."""
opponent = 'B' if player == 'W' else 'W'
return self.checkers[opponent] <= 1
def add_checker(self, player):
"""Place a player's checker on a point."""
self.checkers[player] += 1
def remove_checker(self, player):
"""Remove a player's checker from a point."""
self.checkers[player] -= 1
return point[opponent] <= 1
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace Point class with dict in Backgammon code #798
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Replace Point class with dict in Backgammon code #798
Filter by extension
Viewed files
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing