- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
from itertools import *
lines = tuple ( chain ( ( tuple ( product ( *g ( range ( 3 ) , ( i , ) ) ) ) for g in ( lambda i , j : ( i , j ) , lambda i , j : ( j , i ) ) for i in range ( 3 ) ) , ( ( ( 0 , 0 ) , ( 1 , 1 ) , ( 2 , 2 ) ) , ( ( 2 , 0 ) , ( 1 , 1 ) , ( 0 , 2 ) ) ) ) )
def aimove ( table , i , j ) :
from random import choice
possiblewin = ( lambda x : ( lambda f : ( lambda x : len ( x ) and x [ 0 ] ) ( tuple ( filter ( lambda x : x , map ( f , lines ) ) ) ) ) ( lambda k : 2 == sum ( table.get ( i ) == x for i in k ) and ( lambda e : len ( e ) == 1 and e [ 0 ] ) ( tuple ( i for i in k if not table.get ( i ) ) ) ) )
return ( ( 1 , 1 ) if ( 1 , 1 ) not in table.keys() else possiblewin ( -1 ) or possiblewin ( 1 ) or ( lambda : ( lambda x : x if table.get ( x ) == None else ( lambda x : len ( x ) and x [ 0 ] ) ( tuple ( filter ( lambda x : not table.get ( x ) , permutations ( ( 0 , 2 ) ) ) ) ) ) ( ( 2 * ( i == 0 ) , 2 * ( j == 0 ) ) ) ) () or ( lambda : choice ( tuple ( filter ( lambda x : x not in table.keys() , product ( *tee ( range ( 3 ) ) ) ) ) ) ) () )
iseog = lambda table : ( lambda x : len ( x ) and x [ 0 ] ) ( tuple ( filter ( lambda x : abs ( x ) == 3 , ( sum ( table [ ij ] for ij in keys if table.get ( ij ) ) for keys in lines ) ) ) ) or len ( table ) >= 9
table = {}
eog = 0
while not eog :
i , j = map ( int , input ( "введите координаты: " ) .split() )
if ( i , j ) in table.keys() :
print ( "эта клетка занята" )
continue
if i not in range ( 3 ) or j not in range ( 3 ) :
print ( "неправильные координаты" )
continue
table [ i , j ] = 1
eog = iseog ( table )
if not eog :
table [ aimove ( table , i , j ) ] = -1
eog = iseog ( table )
for ij in product ( *tee ( range ( 3 ) ) ) :
print ( ( " " , "x" , "o" ) [ table.get ( ij ) or 0 ] , end = ( " | " , " | " , "\n" ) [ ij [ 1 ] ] )
if ij [ 0 ] < 2 and ij [ 1 ] == 2 :
print ( "--+---+--" )
print ( ( "ничья. тебе везёт ( пока что )" , "ты победил. ах ты жульник!" , "ты продул, а я победил. бе-бе-бе!" ) [ eog // 3 ] )
Лямбда. Лямбда. Хуямбда.