Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/computer.py
diff options
context:
space:
mode:
Diffstat (limited to 'computer.py')
-rwxr-xr-xcomputer.py49
1 files changed, 29 insertions, 20 deletions
diff --git a/computer.py b/computer.py
index 87c2f87..e6fd630 100755
--- a/computer.py
+++ b/computer.py
@@ -1,6 +1,7 @@
#!/usr/bin/env python
-import elements
+from elements import *
+import random
class Computer:
@@ -12,7 +13,7 @@ class Computer:
@param letters: List of the Letters to use.
'''
- self.__letters = letters
+ self.__letters = bag.remove_letters()
def get_letters(self):
@@ -45,28 +46,36 @@ class Computer:
self.__letters.append(letter)
- def add_letter_from_bag(self, bag, amount = 0):
- ''' Add new Letters to the list of Letters.
+ def swap_letters(self, bag, amount=0):
+ ''' Return the given amount of Letters to the bag, and take
+ the same amount from the bag.
- @param bag: the bag which contains the Letters.
- @amount: the amount.
+ @param bag: the bag
+ @param amount: the amount.
+ @return: True if it is possible otherwise False.
'''
- 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...
-
-
+ from_bag = bag.remove_letters(amount)
+ if from_bag == -1:
+ return False
+ to_bag = []
+ i = 0
+ amount = len(from_bag)
+ while i < amount:
+ for j in range(0, self.letters_length()):
+ if random.randint(0, 1) and i < amount:
+ l = self.get_letter_at(j)
+ to_bag.append(l)
+ self.get_letters().remove(l)
+ i += 1
+ bag.add_letters(to_bag)
+ for l in from_bag:
+ self.add_letter(l)
+ return True
+
+
+
def make_move(self, board, dict, moves):
''' Function which calculates the move that the computer
will make.