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-24 02:58:37 (GMT)
committer Jorge Ramírez <jorgeramirez1990@gmail.com>2010-05-24 02:58:37 (GMT)
commit64d7e61e725eaa12ac49a0e97bc05b29c9a21c68 (patch)
tree30277aaea71eea758c41d931d0a991058627e2f3
parent8975788adef4bea10acc3736f226ddb8b381c309 (diff)
Drafted the make_move function of the computer module.
I also added the follow functions (without implementation yet): can_form_a_word, in utility module search_words_that_match, in utility module try_move, in Move class.
-rwxr-xr-xcomputer.py30
-rwxr-xr-xelements.py22
-rwxr-xr-xutility.py35
3 files changed, 75 insertions, 12 deletions
diff --git a/computer.py b/computer.py
index 7a40006..a41d7fe 100755
--- a/computer.py
+++ b/computer.py
@@ -56,21 +56,33 @@ class Computer:
self.add_letter(letter)
- def make_move(self, board, moves):
+ def make_move(self, board, dict, moves):
''' Function which calculates the move that the computer
will make.
@param board: the current gameboard
+ @param dict: the dictionary
@param moves: the list of Moves that were made along the game.
+ @return: the Move made.
'''
- # calcular movimiento
- # insertar en la tabla el movimiento
- new_move = []
-
- # implementar ......
-
-
-
+ move = Move()
+ for i in range(0, board.get_size()):
+ for j in range(0, board.get_size()):
+ if not board.is_tile_empty(i, j):
+ letter = board.get_value_at(i, j)
+ criterion, type = utility.can_form_a_word(board,
+ self.get_letters(),
+ letter, i, j)
+ words = utility.search_words_that_match(criterion,
+ dict)
+ for w in words:
+ possible = move.try_move(board, w, type, i, j)
+ if possible:
+ move.calculate_score()
+ return move
+ # probar intercambiar letras.
+ # else pasar turno.
+ # to be continued..
diff --git a/elements.py b/elements.py
index 0ea1013..2e57470 100755
--- a/elements.py
+++ b/elements.py
@@ -21,7 +21,7 @@ class Letter:
@param character: the new letter string value
'''
- if(character == ""):
+ if(character == " "):
self.__is_blank = True
self.__character = character
@@ -174,7 +174,9 @@ class Board:
@param column: column on the board
@return: True or False
'''
- return (self.get_value_at(row, column) == "")
+ return (self.get_value_at(row, column) == "")
+
+
@@ -316,6 +318,21 @@ class Move:
'''
return self.length() == 0
+
+ def try_move(self, board, word, type, row, column):
+ ''' Try to insert the given word into the board.
+
+ @param board: the gameboard
+ @param word: the word to insert
+ @param type: the type of the letter, see the
+ utility.can_form_a_word function.
+ @param row: the row in the gameboard.
+ @param column: the column in the gameboard.
+ @return: True if it is possible and also valid to insert
+ the given word into the gameboard, otherwise False.
+ '''
+ # implementar....
+
class Bag:
''' Bag represents a "Bag" of Letters. It contains a dictionary
@@ -351,3 +368,4 @@ class Bag:
def get_bag_letters(self):
''' Get the bag of letters '''
return self.__bag_letters
+
diff --git a/utility.py b/utility.py
index 03731ab..338d2b4 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
@@ -67,3 +67,36 @@ def search_word(lenguage = constants.DEFAULT_LENGUAGE, word, dict):
if not l2:
return False
return True
+
+def can_form_a_word(board, letters,letter, posx, posy):
+ ''' Check if the given letter can be used to form a new word
+ on the board.
+
+ @param board: the gameboard
+ @param letters: the list of letters to use.
+ @param letter: the letter at [row][column] on the board
+ @param posx: x-possition [row]
+ @param posy: y-possition [column]
+ @return: A tuple containing a regular expresion to use as a
+ pattern to search in the dictionary and the type of
+ the given letter. The possible types are:
+ - First letter of the word
+ - Middle letter.
+ - Last letter.
+ '''
+ # implementar...
+
+def search_words_that_match(criterion):
+ ''' Look for words in the dictionary that match with the given
+ pattern
+
+ @param criterion: the pattern
+ @param dict: the dictionary
+ @return: the list of words that matched
+ '''
+ #implementar...
+
+
+
+
+