Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJorge Ramírez <jorgeramirez1990@gmail.com>2010-05-27 01:28:25 (GMT)
committer Jorge Ramírez <jorgeramirez1990@gmail.com>2010-05-27 01:28:25 (GMT)
commit10f8acfb2f1ab8e9601135f67f3052e028c33def (patch)
treeba4ea9d9716a0e5f4d450f4a92961d5232aa5c7b
parent21a508ad70d97cd34dd1e1cd80f3018e6d25c1ce (diff)
Added new modules, game and user.
I also implemented some functions and changed some things. The Lorenas' part I didn't include yet, because I've not have so much time, I will do it as far as I can.
-rwxr-xr-xcomputer.py11
-rwxr-xr-xelements.py26
-rw-r--r--game.py69
-rw-r--r--user.py59
-rwxr-xr-xutility.py6
5 files changed, 160 insertions, 11 deletions
diff --git a/computer.py b/computer.py
index 55119e1..87c2f87 100755
--- a/computer.py
+++ b/computer.py
@@ -56,6 +56,17 @@ class Computer:
self.add_letter(letter)
+ def return_letters_to_bag(self, bag, amount = 0):
+ ''' Return Letters to the bag.
+
+ @param bag: the bag which contains the Letters.
+ @amount: the amount.
+ '''
+ # implementar...
+
+
+
+
def make_move(self, board, dict, moves):
''' Function which calculates the move that the computer
will make.
diff --git a/elements.py b/elements.py
index 2e57470..56d606a 100755
--- a/elements.py
+++ b/elements.py
@@ -346,25 +346,35 @@ class Bag:
def remove_letters(self, amount = constants.DEFAULT_AMOUNT_LETTERS):
- ''' Removes letters from the bag
+ ''' Removes Letters from the bag
@param size: the amount of letters that are going to be removed
@return: the letters removed.
'''
+ # format "letter": (count, score)
removed = []
-
-
- # implementar....
-
+ i = 0
+ while i < amount:
+ for key, data in self.get_bag_letters().items():
+ if random.randint(0 , 1) and i < amount:
+ if data[0] > 0:
+ removed.append(Letter(key, data[1]))
+ self.get_bag_letters()[key] = (data[0] - 1, data[1])
+ i = i + 1
return removed
-
+
+
def add_letters(self, letters):
''' Add letters to the bag
- @param letters: the list of Letters that are going to be added
+ @param letters: the list of letters that are going to be added
'''
- # implementar....
+ for l in letters:
+ count , score = self.get_bag_letters()[l]
+ self.get_bag_letters()[l] = (count + 1, score)
+
+
def get_bag_letters(self):
''' Get the bag of letters '''
return self.__bag_letters
diff --git a/game.py b/game.py
new file mode 100644
index 0000000..87f40fb
--- /dev/null
+++ b/game.py
@@ -0,0 +1,69 @@
+#!/usr/bin/env python
+
+import user
+import computer
+import elements
+import constants
+import utility
+
+class Game:
+ def __init__(self):
+ self.board = Board()
+ self.bag = Bag()
+ self.dict = utility.get_dictionary()
+ self.user = User(self.bag)
+ self.computer = Computer(self.bag)
+ self.moves_log = []
+
+
+ def get_user_letters(self):
+ ''' Return the list of user's Letters
+
+ @return: the list of user's Letters.
+ '''
+ return self.user.get_letters()
+
+ def get_computer_letters(self):
+ ''' Return the list of computer's Letters
+
+ @return: the list of computer's Letters.
+ '''
+ return self.computer.get_letters()
+
+ def get_user(self):
+ return self.user
+
+ def get_computer(self):
+ return self.computer
+
+ def computer_make_move(self):
+ return self.computer.make_move(self.board,
+ self.dict,
+ self.moves_log)
+
+
+ def get_user_char_letters(self):
+ ''' Return the list of user's letters, only the character
+ atribute of the Letter object.
+
+ @return: the list of user's letters.
+ '''
+ list = []
+ l = self.user.get_letters()
+ for e in l:
+ list.append(e.get_character())
+ return list
+
+
+
+ def get_computer_char_letters(self):
+ ''' Return the list of user's letters, only the character
+ atribute of the Letter object.
+
+ @return: the list of user's letters.
+ '''
+ list = []
+ l = self.computer.get_letters()
+ for e in l:
+ list.append(e.get_character())
+ return list
diff --git a/user.py b/user.py
new file mode 100644
index 0000000..09318e8
--- /dev/null
+++ b/user.py
@@ -0,0 +1,59 @@
+#!/usr/bin/env python
+class User:
+ def __init__(self, bag):
+ ''' Initialize the Computer class.
+
+ @param bag: the bag with letters.
+ '''
+ self.__letters = bag.remove_letters()
+
+
+ def get_letters(self):
+ ''' Return the list of Letters.
+
+ @return: the list of elements.
+ '''
+ return self.__letters
+
+ def letters_length(self):
+ ''' Return the length of the list of Letters.
+
+ @return: the number of elements.
+ '''
+ return len(self.__letters)
+
+ def get_letter_at(self, index):
+ ''' Get the letter at the specified index of the list.
+
+ @param index: the index
+ @return: the Letter
+ '''
+ return self.__letter[index]
+
+ def add_letter(self, letter):
+ ''' Add a new Letter to the list of Letters.
+
+ @param letter: the new Letter.
+ '''
+ self.__letters.append(letter)
+
+
+ def add_letter_from_bag(self, bag, amount = 0):
+ ''' Add new Letters to the list of Letters.
+
+ @param bag: the bag which contains the Letters.
+ @amount: the amount.
+ '''
+ new_letters = bag.remove_letters(amount)
+ for letter in new_letters:
+ self.add_letter(letter)
+
+
+ def return_letters_to_bag(self, bag, amount = 0):
+ ''' Return Letters to the bag.
+
+ @param bag: the bag which contains the Letters.
+ @amount: the amount.
+ '''
+ # implementar...
+
diff --git a/utility.py b/utility.py
index 5118411..417b7a6 100755
--- a/utility.py
+++ b/utility.py
@@ -17,7 +17,7 @@ def create_board(size):
for i in range(0, size):
row = []
for j in range(0, size):
- row.append("")
+ row.append(" ")
board.append(row)
return board
@@ -55,12 +55,12 @@ def get_dictionary(lenguage = constants.DEFAULT_LENGUAGE):
dict = file.readlines()
return dict
-def search_word(lenguage = constants.DEFAULT_LENGUAGE, word, dict):
+def search_word(word, dict, lenguage = constants.DEFAULT_LENGUAGE):
''' Look for the specified word in the dictionary
- @param lenguage: the lenguage.
@param word: word to look for
@param dict: the dictionary.
+ @param lenguage: the lenguage.
@return: True or False
'''
l2 = filter(lambda n: re.match(word, capitalize_word(n)), dict)