|
@@ -71,38 +71,59 @@ class Game:
|
|
|
|
|
|
|
|
def check_word(self, word):
|
|
def check_word(self, word):
|
|
|
if word not in word_list:
|
|
if word not in word_list:
|
|
|
- return False
|
|
|
|
|
-
|
|
|
|
|
- previous_matches = 0
|
|
|
|
|
- previous = list(self.current_word)
|
|
|
|
|
- current = list(word)
|
|
|
|
|
- temp_current = current.copy()
|
|
|
|
|
-
|
|
|
|
|
- for letter in temp_current:
|
|
|
|
|
- if letter in previous:
|
|
|
|
|
- previous.remove(letter)
|
|
|
|
|
- current.remove(letter)
|
|
|
|
|
- previous_matches += 1
|
|
|
|
|
- if previous_matches == self.match_amount:
|
|
|
|
|
- break
|
|
|
|
|
-
|
|
|
|
|
- if previous_matches < self.match_amount and previous:
|
|
|
|
|
- return False
|
|
|
|
|
-
|
|
|
|
|
- temp_tiles = self.current_player.tiles.copy()
|
|
|
|
|
- for letter in current:
|
|
|
|
|
- if letter not in temp_tiles:
|
|
|
|
|
- return False
|
|
|
|
|
|
|
+ return final_word
|
|
|
|
|
+
|
|
|
|
|
+ final_word = {
|
|
|
|
|
+ "valid": False,
|
|
|
|
|
+ "word": [{"letter": letter, "status": 0} for letter in list(word)],
|
|
|
|
|
+ }
|
|
|
|
|
+ temp_player_tiles = self.current_player.tiles.copy()
|
|
|
|
|
+ remaining_letters = []
|
|
|
|
|
+
|
|
|
|
|
+ for item in final_word["word"]:
|
|
|
|
|
+ if item["letter"] in temp_player_tiles:
|
|
|
|
|
+ item["status"] = 1
|
|
|
|
|
+ temp_player_tiles.remove(item["letter"])
|
|
|
|
|
+ else:
|
|
|
|
|
+ remaining_letters.append(item["letter"])
|
|
|
|
|
+
|
|
|
|
|
+ match_count = 0
|
|
|
|
|
+
|
|
|
|
|
+ previous_word = list(self.current_word)
|
|
|
|
|
+ for letter in remaining_letters.copy():
|
|
|
|
|
+ if letter in previous_word:
|
|
|
|
|
+ remaining_letters.remove(letter)
|
|
|
|
|
+ previous_word.remove(letter)
|
|
|
|
|
+ for item in final_word["word"]:
|
|
|
|
|
+ if item["letter"] == letter and not item["status"]:
|
|
|
|
|
+ item["status"] = 2
|
|
|
|
|
+ match_count += 1
|
|
|
|
|
+
|
|
|
|
|
+ # TODO: Somehow remain invalid if there's anything left in the remaining_letters list
|
|
|
|
|
+
|
|
|
|
|
+ if match_count < self.match_amount:
|
|
|
|
|
+ for item in final_word["word"]:
|
|
|
|
|
+ if item["letter"] in previous_word and item["status"] == 1:
|
|
|
|
|
+ item["status"] = 2
|
|
|
|
|
+ match_count += 1
|
|
|
|
|
+ temp_player_tiles.append(item["letter"])
|
|
|
|
|
+ if match_count == self.match_amount:
|
|
|
|
|
+ break
|
|
|
|
|
+
|
|
|
|
|
+ if (
|
|
|
|
|
+ match_count == self.match_amount or not self.current_word
|
|
|
|
|
+ ) and not remaining_letters:
|
|
|
|
|
+ final_word["valid"] = True
|
|
|
|
|
|
|
|
- temp_tiles.remove(letter)
|
|
|
|
|
-
|
|
|
|
|
- self.current_player.tiles = temp_tiles
|
|
|
|
|
score = 0
|
|
score = 0
|
|
|
for letter in list(word):
|
|
for letter in list(word):
|
|
|
score += int(letters_dict[letter]["tile_value"])
|
|
score += int(letters_dict[letter]["tile_value"])
|
|
|
- self.current_word = word
|
|
|
|
|
- self.change_turn()
|
|
|
|
|
- return score
|
|
|
|
|
|
|
+ final_word["score"] = score
|
|
|
|
|
+ if final_word["valid"]:
|
|
|
|
|
+ self.current_word = word
|
|
|
|
|
+ self.current_player.tiles = temp_player_tiles
|
|
|
|
|
+ self.change_turn()
|
|
|
|
|
+ return final_word
|
|
|
|
|
|
|
|
def discard_letter(self, letter):
|
|
def discard_letter(self, letter):
|
|
|
if letter not in self.current_player.tiles:
|
|
if letter not in self.current_player.tiles:
|