// File: bjohnsonfl[P]Overhead-Chess-Engine-/position.cpp
// Function: position::setboard()
void position::setboard(){
    for(square sq =a1; sq < numOfSq; sq++)
    {
        board[sq] = not_piece;
    }
    
    for(piece p = w_pawn; p<numOfPieces ; p++ )
    {
        pieces[p] = 0ULL;
    }
    allWhitePieces = 0ULL;
    allBlackPieces = 0ULL;
    allPieces = allWhitePieces | allBlackPieces;
    
   
    /*
     position fen rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1 moves d2d4 e7e6 c1f4 g8f6 g1f3 b8c6 a2a3 f8d6 f4d6 c7d6 e2e3 d8a5 d1d2 a5h5 f1d3 h7h6 h2h3 e8g8 c2c4 d6d5 b1c3 d5c4 d3c4 d7d5 c4e2 c6a5 d2c2 a5c6 f3d2 h5h4 d2f3 h4h5 e1c1 c8d7 f3e5 h5g5 e5d7 f6d7 e2f3 a8c8 c2a4 d7b6 a4b3 f7f5 h3h4 g5f6 c1b1 f5f4 c3b5 f4e3 f2e3 f6f5 b1a1 c6a5 b3d3 c8c1 a1a2 f5d3 d1d3 c1h1 h4h5 a5c6 f3g4 e6e5 d4e5 c6e5 g4e6 g8h8 d3c3 h1h5 c3c7 e5c6 c7b7 c6d8 b7e7 h5e5 b5d4 a7a6 g2g4 e5e3 d4f5 e3e6 e7g7 d8f7 f5d4 e6f6 d4f5 b6c4 f5d4 h8g7 d4f5 g7g6 f5e7 g6g5 e7c6 g5g4 c6e5 g4g3 e5d3 c4b2 a2b2 f6f1 b2c3 f1a1 c3d4 a1a3 d4d5 a3d3 d5e4 d3d1 e4e3 d1a1 e3d4 a1b1 d4c4 b1a1 c4c3 a1b1 c3c2 b1a1 c2b2 a1b1 b2b1 f8a8 b1b2 a8a7 b2b3 a7b7 b3c4 b7b1 c4c3 b1a1 c3b2 a1b1 b2b1 a6a5 b1b2 a5a4 b2a3 h6h5 a3a4 h5h4 a4b4 h4h3 b4c3 h3h2 c3d4 h2h1q d4e3 h1a1 e3e2 a1b1 e2d2 b1a1 d2c2
     
      position startpos moves d2d4 e7e6 c1f4 g8f6 g1f3 b8c6 a2a3 f8d6 f4d6 c7d6 e2e3 d8a5 d1d2 a5h5 f1d3 h7h6 h2h3 e8g8 c2c4 d6d5 b1c3 d5c4 d3c4 d7d5 c4e2 c6a5 d2c2 a5c6 f3d2 h5h4 d2f3 h4h5 e1c1 c8d7 f3e5 h5g5 e5d7 f6d7 e2f3 a8c8 c2a4 d7b6 a4b3 f7f5 h3h4 g5f6 c1b1 f5f4 c3b5 f4e3 f2e3 f6f5 b1a1 c6a5 b3d3 c8c1 a1a2 f5d3 d1d3 c1h1 h4h5 a5c6 f3g4 e6e5 d4e5 c6e5 g4e6 g8h8 d3c3 h1h5 c3c7 e5c6 c7b7 c6d8 b7e7 h5e5 b5d4 a7a6 g2g4 e5e3 d4f5 e3e6 e7g7 d8f7 f5d4 e6f6 d4f5 b6c4 f5d4 h8g7 d4f5 g7g6 f5e7 g6g5 e7c6 g5g4 c6e5 g4g3 e5d3 c4b2 a2b2 f6f1 b2c3 f1a1 c3d4 a1a3 d4d5 a3d3 d5e4 d3d1 e4e3 d1a1 e3d4 a1b1 d4c4 b1a1 c4c3 a1b1 c3c2 b1a1 c2b2 a1b1 b2b1 f8a8 b1b2 a8a7 b2b3 a7b7 b3c4 b7b1 c4c3 b1a1 c3b2 a1b1 b2b1 a6a5 b1b2 a5a4 b2a3 h6h5 a3a4 h5h4 a4b4 h4h3 b4c3 h3h2 c3d4 h2h1q d4e3 h1a1 e3e2 a1b1 e2d2 b1a1 d2c2
     
     */
   
    std::string fen= "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
//std::string fen = "n1n5/PPPk4/8/8/8/8/4Kppp/5N1N b - - 0 1";
   
    
   // std::string fen =  "r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1";
//std::string fen ="r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/5Q1p/PPPBBPPP/RN2K2R b KQkq -";
    
  // std::string fen = "r2k3r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/5Q1p/PPPBBPPP/RN2K2R w KQ -";
    
    
    
 //   std::string fen = "r4rk1/1pp1qppp/p1np1n2/2b1p1B1/2B1P1b1/P1NP1N2/1PP1QPPP/R4RK1 w - - 0 10";
    
    
    
    
  //  std::string fen= "8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - -";
   // std::string fen =  "r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1";
    //test
    //std::string fen = "r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N5/PPPBBPpP/R4K1R w - -";
    
  //  std::string fen = "2p5/2P5/3pq3/1bR2p1p/4N1B1/2b5/2P2p2/8 W - -";
   // std::string fen ="2p5/2P5/3pq3/1bR2p2/4N1B1/2bQ3p/2P2p2/3p4 w - -";
  //std::string fen = "8/8/5P2/1PPpk3/2KP1N2/1bb5/8/8 w - -";
   // std::string fen =  "7p/6P1/P4pp1/1p3PP1/2Pp2p1/p2P4/1P2p3/p4P2 w - -";
    // std::string fen = "8/pppppPpp/1P6/2P4p/4pP2/1pP5/PPPPPPPp/8 w KQkq -";
    //std::string fen = "r2RQn2/PP1pPPPp/8/1P6/1p6/7p/p1Pp1pp1/bBq1NR2 w - -";
    //std::string fen = "8/8/1b2BB2/1Npk4/2K4r/1nP5/1B1R1Q2/6q1 w - -";
   // std::string fen = "8/8/8/4bb2/8/8/8/R3K1nR w - -";
   // std::string fen ="3Q1R2/3rpP1q/b1Qp1kP1/1P4r1/3r1n1B/rP1KP1r1/1r1P4/B2q1Q2 w - -";
    //std::string fen ="r1bqkb1r/pp2p1pp/n7/3pPp2/2pP2nN/PP6/2P1BPPP/RNBQK2R b KQkq d3 0 43";
   // std::string fen = "4R2B/k7/8/3PpP2/3K1P2/5NB1/8/4Q3 w - e6 0 2";
    //std::string fen = "1q2K3/1QP4P/2N5/8/8/8/8/8 w - -";
  //  std::string fen = "k7/1b6/8/3Pp1r1/4K3/8/8/8 w - e6 0 2";
   // std::string fen =  "k6b/2r5/5Q2/8/2P5/2K3Rq/8/8 w - -";
  //  std::string fen = "k7/8/8/3PpP2/8/8/1K6/8 w - e6 0 2";
    fenParser(fen);
    
    
    //debug
    //printAllBitboards();
   // printBoard();
    
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x50(%rbp)
movl $0x0, -0xc(%rbp)
cmpl $0x40, -0xc(%rbp)
jge 0x851c
movq -0x50(%rbp), %rax
movl -0xc(%rbp), %ecx
movl $0xc, (%rax,%rcx,4)
leaq -0xc(%rbp), %rdi
xorl %esi, %esi
callq 0x5a80
jmp 0x84fb
movl $0x0, -0x10(%rbp)
cmpl $0xc, -0x10(%rbp)
jge 0x8549
movq -0x50(%rbp), %rax
movl -0x10(%rbp), %ecx
movq $0x0, 0x100(%rax,%rcx,8)
leaq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x9f80
jmp 0x8523
movq -0x50(%rbp), %rax
movq $0x0, 0x160(%rax)
movq $0x0, 0x168(%rax)
movq 0x160(%rax), %rcx
movq 0x168(%rax), %rdx
orq %rdx, %rcx
movq %rcx, 0x170(%rax)
leaq -0x31(%rbp), %rdi
movq %rdi, -0x58(%rbp)
callq 0x33a0
movq -0x58(%rbp), %rdx
leaq 0x5de5(%rip), %rsi      # 0xe378
leaq -0x30(%rbp), %rdi
callq 0x3b70
jmp 0x859e
leaq -0x31(%rbp), %rdi
callq 0x3230
movq -0x50(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x7b30
jmp 0x85b6
leaq -0x30(%rbp), %rdi
callq 0x3408
addq $0x60, %rsp
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x31(%rbp), %rdi
callq 0x3230
jmp 0x85f1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x3408
movq -0x40(%rbp), %rdi
callq 0x3390
nopw (%rax,%rax)