createCanvas(Math.min(windowWidth,windowHeight),Math.min(windowWidth,windowHeight))
fill(100);noStroke();rect(0,0,width,height)
fill(155);stroke(0);strokeWeight(1)
rect((width/4*i)%width+Math.floor(i/4)%2*height/8,height/8*Math.floor(i/4),width/8,height/8)
fill(255);strokeWeight(3)
for(let i=0;i<pieces[0].length;i++){
noStroke();if(selected[0]==0&&selected[1]==i){
width/16+width/8*pieces[0][i][0],height/16+height/8*pieces[0][i][1],
width/16+width/8*pieces[0][i][0],height/16+height/8*pieces[0][i][1]+height/12
width/16+width/8*pieces[0][i][0]+height/90,height/16+height/8*pieces[0][i][1]+height/12-height/90,
width/16+width/8*pieces[0][i][0],height/16+height/8*pieces[0][i][1]+height/12
width/16+width/8*pieces[0][i][0]-height/90,height/16+height/8*pieces[0][i][1]+height/12-height/90,
width/16+width/8*pieces[0][i][0],height/16+height/8*pieces[0][i][1]+height/12
moves[0].push([pieces[0][i][0],pieces[0][i][1]+1])
moves[1].push([pieces[0][i][0],pieces[0][i][1]+1])
width/16+width/8*pieces[0][i][0],height/16+height/8*pieces[0][i][1],
width/16+width/8*pieces[0][i][0],height/16+height/8*pieces[0][i][1]-height/12
width/16+width/8*pieces[0][i][0]+height/90,height/16+height/8*pieces[0][i][1]-height/12+height/90,
width/16+width/8*pieces[0][i][0],height/16+height/8*pieces[0][i][1]-height/12
width/16+width/8*pieces[0][i][0]-height/90,height/16+height/8*pieces[0][i][1]-height/12+height/90,
width/16+width/8*pieces[0][i][0],height/16+height/8*pieces[0][i][1]-height/12
moves[0].push([pieces[0][i][0],pieces[0][i][1]-1])
moves[1].push([pieces[0][i][0],pieces[0][i][1]-1])
width/16+width/8*pieces[0][i][0],height/16+height/8*pieces[0][i][1],
width/16+width/8*pieces[0][i][0]-width/12,height/16+height/8*pieces[0][i][1]
width/16+width/8*pieces[0][i][0]+height/90-height/12,height/16+height/8*pieces[0][i][1]+height/90,
width/16+width/8*pieces[0][i][0]-width/12,height/16+height/8*pieces[0][i][1]
width/16+width/8*pieces[0][i][0]+height/90-height/12,height/16+height/8*pieces[0][i][1]-height/90,
width/16+width/8*pieces[0][i][0]-width/12,height/16+height/8*pieces[0][i][1]
moves[0].push([pieces[0][i][0]-1,pieces[0][i][1]])
moves[1].push([pieces[0][i][0]-1,pieces[0][i][1]])
width/16+width/8*pieces[0][i][0],height/16+height/8*pieces[0][i][1],
width/16+width/8*pieces[0][i][0]+width/12,height/16+height/8*pieces[0][i][1]
width/16+width/8*pieces[0][i][0]-height/90+height/12,height/16+height/8*pieces[0][i][1]+height/90,
width/16+width/8*pieces[0][i][0]+width/12,height/16+height/8*pieces[0][i][1]
width/16+width/8*pieces[0][i][0]-height/90+height/12,height/16+height/8*pieces[0][i][1]-height/90,
width/16+width/8*pieces[0][i][0]+width/12,height/16+height/8*pieces[0][i][1]
moves[0].push([pieces[0][i][0]+1,pieces[0][i][1]])
moves[1].push([pieces[0][i][0]+1,pieces[0][i][1]])
width/16+width/8*pieces[0][i][0],height/16+height/8*pieces[0][i][1],
width/16+width/8*pieces[0][i][0],height/16+height/8*pieces[0][i][1]-height/12
width/16+width/8*pieces[0][i][0]+height/90,height/16+height/8*pieces[0][i][1]-height/12+height/90,
width/16+width/8*pieces[0][i][0],height/16+height/8*pieces[0][i][1]-height/12
width/16+width/8*pieces[0][i][0]-height/90,height/16+height/8*pieces[0][i][1]-height/12+height/90,
width/16+width/8*pieces[0][i][0],height/16+height/8*pieces[0][i][1]-height/12
moves[0].push([pieces[0][i][0],pieces[0][i][1]-1])
if(pieces[0][i][1]<7&&(Math.abs(pieces[0][i][0]-3.5)>0.5)||pieces[0][i][1]<6){
width/16+width/8*pieces[0][i][0],height/16+height/8*pieces[0][i][1],
width/16+width/8*pieces[0][i][0],height/16+height/8*pieces[0][i][1]+height/12
width/16+width/8*pieces[0][i][0]+height/90,height/16+height/8*pieces[0][i][1]+height/12-height/90,
width/16+width/8*pieces[0][i][0],height/16+height/8*pieces[0][i][1]+height/12
width/16+width/8*pieces[0][i][0]-height/90,height/16+height/8*pieces[0][i][1]+height/12-height/90,
width/16+width/8*pieces[0][i][0],height/16+height/8*pieces[0][i][1]+height/12
moves[0].push([pieces[0][i][0],pieces[0][i][1]+1])
moves[1].push([pieces[0][i][0]-1,pieces[0][i][1]])
moves[1].push([pieces[0][i][0]+1,pieces[0][i][1]])
if(pieces[0][i][1]==0){if(pieces[0][i][0]==3)filled[0]=1;if(pieces[0][i][0]==4)filled[1]=1}
ellipse(width/16+width/8*pieces[0][i][0],height/16+height/8*pieces[0][i][1],height/16,height/16)
for(let i=0;i<pieces[1].length;i++){
noStroke();if(selected[0]==1&&selected[1]==i){
width/16+width/8*pieces[1][i][0],height/16+height/8*pieces[1][i][1],
width/16+width/8*pieces[1][i][0],height/16+height/8*pieces[1][i][1]-height/12
width/16+width/8*pieces[1][i][0]+height/90,height/16+height/8*pieces[1][i][1]-height/12+height/90,
width/16+width/8*pieces[1][i][0],height/16+height/8*pieces[1][i][1]-height/12
width/16+width/8*pieces[1][i][0]-height/90,height/16+height/8*pieces[1][i][1]-height/12+height/90,
width/16+width/8*pieces[1][i][0],height/16+height/8*pieces[1][i][1]-height/12
moves[0].push([pieces[1][i][0],pieces[1][i][1]-1])
moves[1].push([pieces[1][i][0],pieces[1][i][1]-1])
width/16+width/8*pieces[1][i][0],height/16+height/8*pieces[1][i][1],
width/16+width/8*pieces[1][i][0],height/16+height/8*pieces[1][i][1]+height/12
width/16+width/8*pieces[1][i][0]+height/90,height/16+height/8*pieces[1][i][1]+height/12-height/90,
width/16+width/8*pieces[1][i][0],height/16+height/8*pieces[1][i][1]+height/12
width/16+width/8*pieces[1][i][0]-height/90,height/16+height/8*pieces[1][i][1]+height/12-height/90,
width/16+width/8*pieces[1][i][0],height/16+height/8*pieces[1][i][1]+height/12
moves[0].push([pieces[1][i][0],pieces[1][i][1]+1])
moves[1].push([pieces[1][i][0],pieces[1][i][1]+1])
width/16+width/8*pieces[1][i][0],height/16+height/8*pieces[1][i][1],
width/16+width/8*pieces[1][i][0]-width/12,height/16+height/8*pieces[1][i][1]
width/16+width/8*pieces[1][i][0]+height/90-height/12,height/16+height/8*pieces[1][i][1]+height/90,
width/16+width/8*pieces[1][i][0]-width/12,height/16+height/8*pieces[1][i][1]
width/16+width/8*pieces[1][i][0]+height/90-height/12,height/16+height/8*pieces[1][i][1]-height/90,
width/16+width/8*pieces[1][i][0]-width/12,height/16+height/8*pieces[1][i][1]
moves[0].push([pieces[1][i][0]-1,pieces[1][i][1]])
moves[1].push([pieces[1][i][0]-1,pieces[1][i][1]])
width/16+width/8*pieces[1][i][0],height/16+height/8*pieces[1][i][1],
width/16+width/8*pieces[1][i][0]+width/12,height/16+height/8*pieces[1][i][1]
width/16+width/8*pieces[1][i][0]-height/90+height/12,height/16+height/8*pieces[1][i][1]+height/90,
width/16+width/8*pieces[1][i][0]+width/12,height/16+height/8*pieces[1][i][1]
width/16+width/8*pieces[1][i][0]-height/90+height/12,height/16+height/8*pieces[1][i][1]-height/90,
width/16+width/8*pieces[1][i][0]+width/12,height/16+height/8*pieces[1][i][1]
moves[0].push([pieces[1][i][0]+1,pieces[1][i][1]])
moves[1].push([pieces[1][i][0]+1,pieces[1][i][1]])
width/16+width/8*pieces[1][i][0],height/16+height/8*pieces[1][i][1],
width/16+width/8*pieces[1][i][0],height/16+height/8*pieces[1][i][1]+height/12
width/16+width/8*pieces[1][i][0]+height/90,height/16+height/8*pieces[1][i][1]+height/12-height/90,
width/16+width/8*pieces[1][i][0],height/16+height/8*pieces[1][i][1]+height/12
width/16+width/8*pieces[1][i][0]-height/90,height/16+height/8*pieces[1][i][1]+height/12-height/90,
width/16+width/8*pieces[1][i][0],height/16+height/8*pieces[1][i][1]+height/12
moves[0].push([pieces[1][i][0],pieces[1][i][1]+1])
if(pieces[1][i][1]>0&&(Math.abs(pieces[1][i][0]-3.5)>0.5)||pieces[1][i][1]>1){
width/16+width/8*pieces[1][i][0],height/16+height/8*pieces[1][i][1],
width/16+width/8*pieces[1][i][0],height/16+height/8*pieces[1][i][1]-height/12
width/16+width/8*pieces[1][i][0]+height/90,height/16+height/8*pieces[1][i][1]-height/12+height/90,
width/16+width/8*pieces[1][i][0],height/16+height/8*pieces[1][i][1]-height/12
width/16+width/8*pieces[1][i][0]-height/90,height/16+height/8*pieces[1][i][1]-height/12+height/90,
width/16+width/8*pieces[1][i][0],height/16+height/8*pieces[1][i][1]-height/12
moves[0].push([pieces[1][i][0],pieces[1][i][1]-1])
moves[1].push([pieces[1][i][0]-1,pieces[1][i][1]])
moves[1].push([pieces[1][i][0]+1,pieces[1][i][1]])
if(pieces[1][i][1]==7){if(pieces[1][i][0]==3)filled[2]=1;if(pieces[1][i][0]==4)filled[3]=1}
ellipse(width/16+width/8*pieces[1][i][0],height/16+height/8*pieces[1][i][1],height/16,height/16)
moves[1]=moves[1].filter(x=>Math.abs(x[0]-3.5)>0.5||Math.abs(x[1]-3.5)<3.5)
stroke(255,0,0);strokeWeight(3)
for(let i=0;i<moves[1].length;i++){
for(let j=0;j<pieces[1-selected[0]].length;j++){
if(pieces[1-selected[0]][j][0]==moves[1][i][0]&&pieces[1-selected[0]][j][1]==moves[1][i][1])a=j
width/16+width/8*moves[1][i][0]-width/24,width/16+width/8*moves[1][i][1]+width/24,
width/16+width/8*moves[1][i][0]+width/24,width/16+width/8*moves[1][i][1]-width/24
width/16+width/8*moves[1][i][0]-width/24,width/16+width/8*moves[1][i][1]-width/24,
width/16+width/8*moves[1][i][0]+width/24,width/16+width/8*moves[1][i][1]+width/24
if((filled[0]&&filled[1])||(filled[2]&&filled[3]))noLoop()
let cell = [Math.floor(mouseX/width*8),Math.floor(mouseY/height*8)]
for(let i=0;i<moves[1].length;i++){
if(cell[0]==moves[1][i][0]&&cell[1]==moves[1][i][1]){
for(let j=0;j<pieces[1-selected[0]].length;j++){
if(pieces[1-selected[0]][j][0]==moves[1][i][0]&&pieces[1-selected[0]][j][1]==moves[1][i][1])a=j
pieces[selected[0]][selected[1]][0]=moves[1][i][0]
pieces[selected[0]][selected[1]][1]=moves[1][i][1]
pieces[1-selected[0]]=[...pieces[1-selected[0]].slice(0,a),...pieces[1-selected[0]].slice(a+1,pieces[1-selected[0]].length)]
for(let i=0;i<moves[0].length;i++){
if(cell[0]==moves[0][i][0]&&cell[1]==moves[0][i][1]){
for(let j=0;j<pieces[0].length;j++){
if((j!==selected[1]||selected[0]!==0)&&pieces[0][j][0]==moves[0][i][0]&&pieces[0][j][1]==moves[0][i][1])a=0
for(let j=0;j<pieces[1].length;j++){
if((j!==selected[1]||selected[0]!==1)&&pieces[1][j][0]==moves[0][i][0]&&pieces[1][j][1]==moves[0][i][1])a=0
pieces[selected[0]][selected[1]][0]=moves[0][i][0]
pieces[selected[0]][selected[1]][1]=moves[0][i][1]
for(let i=0;i<pieces[0].length;i++){
if(cell[0]==pieces[0][i][0]&&cell[1]==pieces[0][i][1]){
for(let i=0;i<pieces[1].length;i++){
if(cell[0]==pieces[1][i][0]&&cell[1]==pieces[1][i][1]){
if(tsel[0]==selected[0]&&tsel[1]==selected[1])selected=[0,-1]
if(turn%2!==selected[0])selected=[0,-1]
let cell = [Math.floor(mouseX/width*8),Math.floor(mouseY/height*8)]
for(let i=0;i<moves[1].length;i++){
if(cell[0]==moves[1][i][0]&&cell[1]==moves[1][i][1]){
for(let j=0;j<pieces[1-selected[0]].length;j++){
if(pieces[1-selected[0]][j][0]==moves[1][i][0]&&pieces[1-selected[0]][j][1]==moves[1][i][1])a=j
pieces[selected[0]][selected[1]][0]=moves[1][i][0]
pieces[selected[0]][selected[1]][1]=moves[1][i][1]
pieces[1-selected[0]]=[...pieces[1-selected[0]].slice(0,a),...pieces[1-selected[0]].slice(a+1,pieces[1-selected[0]].length)]
for(let i=0;i<moves[0].length;i++){
if(cell[0]==moves[0][i][0]&&cell[1]==moves[0][i][1]){
for(let j=0;j<pieces[0].length;j++){
if((j!==selected[1]||selected[0]!==0)&&pieces[0][j][0]==moves[0][i][0]&&pieces[0][j][1]==moves[0][i][1])a=0
for(let j=0;j<pieces[1].length;j++){
if((j!==selected[1]||selected[0]!==1)&&pieces[1][j][0]==moves[0][i][0]&&pieces[1][j][1]==moves[0][i][1])a=0
pieces[selected[0]][selected[1]][0]=moves[0][i][0]
pieces[selected[0]][selected[1]][1]=moves[0][i][1]
for(let i=0;i<pieces[0].length;i++){
if(cell[0]==pieces[0][i][0]&&cell[1]==pieces[0][i][1]){
for(let i=0;i<pieces[1].length;i++){
if(cell[0]==pieces[1][i][0]&&cell[1]==pieces[1][i][1]){
if(ttsel[0]==selected[0]&&ttsel[1]==selected[1])selected=[0,-1]
ttsel=[selected[0],selected[1]]
if(turn%2!==selected[0])selected=[0,-1]