print " Simba Chess! " B=[[5,1,0,0,0,0,-1,-5],[2,1,0,0,0,0,-1,-2],[3,1,0,0,0,0,-1,-3], [9,1,0,0,0,0,-1,-9],[8,1,0,0,0,0,-1,-8],[3,1,0,0,0,0,-1,-3], [2,1,0,0,0,0,-1,-2],[5,1,0,0,0,0,-1,-5]] blank = [[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]] king = [[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]] queen = [[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]] rook = [[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]] bishop = [[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]] knight = [[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]] pmove = [[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]] pattack = [[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]] bking = [[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]] bqueen = [[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]] brook = [[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]] bbishop = [[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]] bknight = [[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]] bpmove = [[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]] bpattack = [[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]] check = [[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]] castle =[[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]] en_passent = [[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]] bcheck = [[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]] bcastle = [[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]] ben_passent = [[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]] def sum_boards(board1,board2): return_val=[[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]] for x in range(8): for y in range(8): return_val[x][y] = board1[x][y]+board2[x][y] return return_val KnB = sum_boards(sum_boards(knight ,knight),sum_boards( bishop , bbishop)) QnR = sum_boards(sum_boards(queen , bqueen ),sum_boards( brook , rook)) pawn_war = sum_boards(sum_boards(pmove,pattack),sum_boards(bpmove,bpattack)) def white_check(board): for x in range(8): for y in range(8): if B[x][y]==8: if bqueen[x][y]==0: if brook[x][y]==0: if bbishop[x][y]==0: if bknight[x][y]==0: if bpattack[x][y]==0: return True return False white_checker = sum_boards(sum_boards(sum_boards(bking,bqueen),sum_boards(brook,bbishop)),sum_boards(bknight,bpattack)) black_checker = sum_boards(sum_boards(sum_boards(king,queen),sum_boards(rook,bishop)),sum_boards(knight,pattack)) def print_board(board): for x in range(8): print(str(board[x][0])+" "+str(board[x][1])+" "+str(board[x][2]) + " " + str(board[x][3])+" "+str(board[x][4])+" "+str(board[x][5])+" "+str(board[x][6])+" "+str(board[x][7])) def white_moves(B): for x in range(8): for y in range(8): if B[x][y]==8: ohe = [-1,0,1] for w in ohe: for z in ohe: if x+w>=0 and x+w<8: if y+z>=0 and y+z<8: if B[x+w][y+z]<=0: if white_check[x+w][y+z]==0: king[x+w][y+z]=-B[x+w][y+z] if king[x+w][y+z]==0: king[x+w][y+z]=8 for x in range(8): for y in range(8): if B[x][y]==1: if B[x][y+1]==0: B[x][y+1]=1 B[x][y]=0 if white_check(B): pmove[x][y+1]=1 if y==1: B[x][y+2] = 1 B[x][y+1] = 0 if white_check(B): pmove[x][y+2]=1 B[x][y+1]= 1 B[x][y+2] = 0 B[x][y+1]=0 B[x][y]=1 from math import * for x in range(8): for y in range(8): if B[x][y]==2: for w in range(8): for z in range(8): if abs(x-w)+abs(y-z)==3 and x!=w and z!=y: A = B[w][z] B[w][z]=2 if white_check(B): if A!=0: knight[w][z]=-A if A==0: knight[w][z]=2 B[w][z]=A for x in range(8): for y in range(8): if B[x][y]==3: for z in range(1,1,8): if z ==1: if x+z<8 and y+z<8: A = B[x+z][y+z] B[x+z][y+z] = 3 B[x][y]=0 if white_check(B): bishop[x+z][y+z]=-A if bishop[x+z][y+z]==0: bishop[x+z][y+z]=3 B[x+z][y+z]=A B[x][y]=3 if x-z>-1 and y+z<8: A = B[x-z][y+z] B[x-z][y+z]=3 B[x][y]=0 if white_check(B): bishop[x-z][y+z]=-A if bishop[x-z][y+z]==0: bishop[x-z][y+z]=3 B[x-z][y+z] = A B[x][y]=3 if x-z>-1 and y-z>-1: A = B[x-z][y-z] B[x-z][y-z]=3 B[x][y]=0 if white_check(B): bishop[x-z][y-z]=-A if bishop[x-z][y-z]==0: bishop[x-z][y-z]=3 B[x-z][y-z]=A B[x][y]=3 if x+z<8 and y-z>-1: A = B[x+z][y-z] B[x+z][y-z] = 3 B[x][y]=0 if white_check(B): bishop[x+z][y-z]=-A if bishop[x+z][y-z]==0: bishop[x+z][y-z]=3 B[x][y]=3 B[x+z][y-z]=A if z>1: for w in range(1,1,z): if x+z<8 and y+z<8: if B[x+w][y+w]==0: A = B[x+z][y+z] B[x][y]=0 B[x+z][y+z]=3 if white_check(B): bishop[x+z][y+z]=-A if bishop[x+z][y+z]==0: bishop[x+z][y+z]=3 B[x][y]=3 B[x+z][y+z]=A if x-z>-1 and y+z<8: if B[x-w][y+w]==0: A = B[x-z][y+z] B[x][y]=0 B[x-z][y+z]=3 if white_check(B): bishop[x-z][y+z]=-A if bishop[x-z][y+z]==0: bishop[x-z][y+z]=3 B[x][y]=3 B[x-z][y+z]=A if x-z>-1 and y-z>-1: if B[x-w][y-w]==0: A = B[x-z][y-z] B[x][y]=0 B[x-z][y-z]=3 if white_check(B): bishop[x-z][y-z]=-A if bishop[x-z][y-z]==0: bishop[x-z][y-z]=3 B[x][y]=3 B[x-z][y-z]=A if x+z<8 and y-z>-1: if B[x+w][y-w]==0: A = B[x+z][y-z] B[x+z][y-z]=3 B[x][y]=0 if white_check(B): bishop[x+z][y-z]=-A if bishop[x+z][y-z]==0: bishop[x+z][y-z]=3 B[x][y]=3 B[x+z][y-z]=A print_board(knight)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question