Skip to content

Instantly share code, notes, and snippets.

@Abdulazizsayed
Created February 13, 2018 17:04
Show Gist options
  • Save Abdulazizsayed/c072b350b9ce6d08c29a0697314104a0 to your computer and use it in GitHub Desktop.
Save Abdulazizsayed/c072b350b9ce6d08c29a0697314104a0 to your computer and use it in GitHub Desktop.
def check16(lst):
count1=0
for i in lst:
for z in i:
if(z=='x'):
count1+=1
if(count1==16):
return True
else:
return False
def check(lst):
count=0
lst2=[]
for i in lst:
for z in i:
if(z!='x'):
lst2.append(z)
for i in range(0,len(lst2)):
for j in range(i+1,len(lst2)):
if abs(lst2[i]-lst2[j]) == 4 or abs(lst2[i]-lst2[j]) == 1:
if not((lst2[i]==4 and lst2[j]==5)or(lst2[j]==4 and lst2[i]==5)or(lst2[i]==8 and lst2[j]==9)or(lst2[j]==8 and lst2[i]==9)or(lst2[i]==12 and lst2[j]==13)or(lst2[i]==12 and lst2[j]==13)or lst2[i]>16 or lst2[i]<1 or lst2[j]>16 or lst2[j]<1):
return False
return True
q=input("Enter first player name : ")
a=input("Enter second player name : ")
lst=[[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]
print(lst[0][0],' ',lst[0][1],' ',lst[0][2],' ',lst[0][3])
print(lst[1][0],' ',lst[1][1],' ',lst[1][2],' ',lst[1][3])
print(lst[2][0],'',lst[2][1],'',lst[2][2],'',lst[2][3])
print(lst[3][0],'',lst[3][1],'',lst[3][2],'',lst[3][3])
while(True):
print(q," : ")
x=input()
try:
x=int(x)
except:
print('wrong input')
continue
y=input()
try:
y=int(y)
except:
print('wrong input')
continue
if((x==4 and y==5)or(y==4 and x==5)or(x==8 and y==9)or(y==8 and x==9)or(x==12 and y==13)or(x==12 and y==13)or x>16 or x<1 or y>16 or y<1 or lst[(x-1)//4][(x%4)-1]=='x' or lst[(y-1)//4][(y%4)-1]=='x'):
print ('wrong inputs')
continue
if(abs(x-y)==1 or abs(x-y)==4):
lst[(x-1)//4][(x%4)-1]='x'
lst[(y-1)//4][(y%4)-1]='x'
print(lst[0][0],' ',lst[0][1],' ',lst[0][2],' ',lst[0][3])
print(lst[1][0],' ',lst[1][1],' ',lst[1][2],' ',lst[1][3])
print(lst[2][0],' ',lst[2][1],' ',lst[2][2],' ',lst[2][3])
print(lst[3][0],' ',lst[3][1],' ',lst[3][2],' ',lst[3][3])
else:
print ('wrong inputs')
continue
if(check16(lst)):
print("draw")
break
if(check(lst)):
print ('player 1 is the winner')
break
else:
zizo=False
while(True):
print(a," : ")
x=input()
try:
x=int(x)
except:
print('wrong input')
continue
y=input()
try:
y=int(y)
except:
print('wrong input')
continue
if((x==4 and y==5)or(y==4 and x==5)or(x==8 and y==9)or(y==8 and x==9)or(x==12 and y==13)or(x==12 and y==13)or x>16 or x<1 or y>16 or y<1 or lst[(x-1)//4][(x%4)-1]=='x' or lst[(y-1)//4][(y%4)-1]=='x'): #in c++ is(|| lst[(x-1)/4][(x%4)-1]==c or lst[(y-1)/4][(y%4)-1]==c)
print ('wrong inputs')
continue
if(abs(x-y)==1 or abs(x-y)==4):
lst[(x-1)//4][(x%4)-1]='x'
lst[(y-1)//4][(y%4)-1]='x'
print(lst[0][0],' ',lst[0][1],' ',lst[0][2],' ',lst[0][3])
print(lst[1][0],' ',lst[1][1],' ',lst[1][2],' ',lst[1][3])
print(lst[2][0],' ',lst[2][1],' ',lst[2][2],' ',lst[2][3])
print(lst[3][0],' ',lst[3][1],' ',lst[3][2],' ',lst[3][3])
else:
print ('wrong inputs')
continue
if(check16(lst)):
print("draw")
zizo=True
break
break
if zizo:
break
if(check(lst)):
print("player 2 is the winner")
break
@Abdulazizsayed
Copy link
Author

my first game

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment