Форум сайта python.su
0
Доброго времени суток!
Пишу игру крестики-нолики, а пока только функцию, вычисляющую по коду(строка с координатами ходов, например, a1b2c1a3) игры, встали ли крестики или нолики в линию.
def result(code): number_of_lettercode = 0 number_of_symbol = 0 player1 = [None]*5 player2 = [None]*5 result = '' while number_of_lettercode<len(code): player1[number_of_symbol] = code[number_of_lettercode:number_of_lettercode+2] number_of_symbol=number_of_symbol+1 number_of_lettercode=number_of_lettercode+4 number_of_lettercode = 2 number_of_symbol = 0 while number_of_lettercode<len(code): player2[number_of_symbol] = code[number_of_lettercode:number_of_lettercode+2] number_of_symbol=number_of_symbol+1 number_of_lettercode=number_of_lettercode+4 if 'a1' and 'b1' and 'c1' in player1: result = 'player1' if 'a2' and 'b2' and 'c2' in player1: result = 'player1' if 'a3' and 'b3' and 'c3' in player1: result = 'player1' if 'a1' and 'a2' and 'a3' in player1: result = 'player1' if 'b1' and 'b2' and 'b3' in player1: result = 'player1' if 'c1' and 'c2' and 'c3' in player1: result = 'player1' if 'a1' and 'b2' and 'c3' in player1: result = 'player1' if 'a3' and 'b2' and 'c1' in player1: result = 'player1' print(player1) print(player2) print(result) coord = input('input code, please ') result(coord)
if 'a1' and 'b1' in player1: if 'c1' in player1: result = 'player1'
Офлайн
53
для начала разобрался бы как работает оператор and, а потом говорил про баги
Офлайн
857
>>> lst = ['a', 'b1', 'b', 'c1', 'c', 'a1'] >>> {'a1', 'b1', 'c1'}.difference(lst) == set() True >>> >>> lst = ['a', 'b', 'c1', 'c', 'a1'] >>> {'a1', 'b1', 'c1'}.difference(lst) == set() False >>>
Отредактировано py.user.next (Фев. 28, 2015 02:24:13)
Офлайн
221
Oleg_Sizon
вдогонку к предыдущим постам следующий код вам на анализ:
>>> 1 and 3 3 >>> 3 and 1 1 >>> 0 and 3 0 >>> 3 and 0 0
Офлайн
0
Спасибо за ответы! Все осознал 
Офлайн