Esempio n. 1
0
 def whose_turn(self):
     if self.winner in [1, 2]:
         return 3 - self.winner
     if self.words.my().count() < self.words.him().count():
         return get_player()
     if self.words.my().count() > self.words.him().count():
         return 3 - get_player()
     return self.first_move
Esempio n. 2
0
 def guess_word(self, word):
     if not self.player_turn(word):
         return
     if self.comp:
         if self.winner == 3 - get_player():
             return  # комп уже выиграл, ходить не нужно
         self.comp_turn()
Esempio n. 3
0
 def check_winning(self, score1, score2, last_player):
     if last_player == get_player():
         word = self.him_word()
     else:
         word = self.my_word()
     if score1 == score2 == len(word):
         if self.winner == -1:
             self.winner = last_player
             self.save()
         else:
             if self.words.my().count() < self.words.him().count():
                 self.winner = get_player()
             elif self.words.my().count() > self.words.him().count():
                 self.winner = 3 - get_player()
             else:
                 self.winner = WINNER_DRAW
             self.finished = True
             self.save()
Esempio n. 4
0
 def player_turn(self, word):
     player = get_player()
     word = process_word(word)
     him_word = self.him_word()
     if len(word) != len(him_word):
         return  # todo: message!
     score1 = self.get_score1(word, him_word)
     score2 = self.get_score2(word, him_word)
     WordOld.objects.create(game=self, player=player, word=word,
                            score1=score1, score2=score2)
     self.check_winning(score1, score2, player)
     return True
Esempio n. 5
0
 def comp_turn(self):
     player = 3 - get_player()
     word = ComputerLogic(self, player, len(self.my_word())).guess()
     if not word:
         return
     word = process_word(word)
     my_word = self.my_word()
     score1 = self.get_score1(word, my_word)
     score2 = self.get_score2(word, my_word)
     WordOld.objects.create(game=self, player=player, word=word,
                            score1=score1, score2=score2)
     ComputerLogic(self, player, len(self.my_word()))
     self.check_winning(score1, score2, player)
Esempio n. 6
0
 def my_turns(self):
     player = get_player()
     return self.get_turns(player)
Esempio n. 7
0
 def him_word(self, value=None):
     player = 3 - get_player()
     if value:
         self.set_word(player, value)
     return self.get_word(player)
Esempio n. 8
0
 def him_win(self):
     return self.winner == 3 - get_player()
Esempio n. 9
0
 def my_win(self):
     return self.winner == get_player()
Esempio n. 10
0
 def him_turn(self):
     return self.ready() and self.whose_turn() == 3 - get_player()
Esempio n. 11
0
 def my_turn(self):
     return self.ready() and self.whose_turn() == get_player()
Esempio n. 12
0
 def him_turns(self):
     player = 3 - get_player()
     return self.get_turns(player)
Esempio n. 13
0
 def him(self):
     return self.player(3 - get_player())
Esempio n. 14
0
 def my(self):
     return self.player(get_player())