Created
July 26, 2012 08:55
-
-
Save dylnuge/3181094 to your computer and use it in GitHub Desktop.
Really basic dict-based board
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
#! /usr/bin/python | |
class Board: | |
def __init__(self): | |
self.board = {} | |
def add_to_board(self, item, position): | |
# Simple function, adds something to the board at position | |
# where position is a tuple, returns True if add is successful | |
if get_item_at(position) == None: | |
self.board[position] = item | |
return True | |
else: | |
return False | |
def get_item_at(self, position): | |
# Return object or None | |
if position in self.board: | |
return self.board[position] | |
else: | |
return None | |
def remove_item_at(self, position): | |
# Stupid remove. Fails silently | |
if position in self.board: | |
del self.board[position] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment