// File: AngelPn[P]L5R-card_game/src/GameBoard.cpp
// Function: GameBoard::gameplay()
void GameBoard::gameplay(){
	int winner= -1;

	while(1){ //Rounds until winner is found
		cout<< "\033[1;35mSTARTING PHASE\033[0m"<< endl;

		for(int i=0; i< players.size(); i++){
			if(players[i]->give_no_provinces()== 0)
				continue;
			players[i]->startingPhase();
		}

		cout<< "\033[1;35mEQUIPMENT PHASE\033[0m"<< endl;
		for(int i=0; i< players.size(); i++){
			if(players[i]->give_no_provinces()== 0)
				continue;
			players[i]->equipPhase();
		}

		cout<< "\033[1;35mBATTLE PHASE\033[0m"<< endl;
		for(int i=0; i< players.size(); i++){
			if(players[i]->give_no_provinces()== 0)
				continue;

				cout << "Player: " << players[i]->name << " is playing " << endl;
				cout << "Battle Phase ..." << endl << endl;
				if (!players[i]->hasArmy()){
					cout << "No army found, phase is skipped :(" << endl << endl;
					continue;
				}

			char c;
			cout<< "Defense or Battle? [Type D/B]: ";
			cin>> c;

			if(c== 'D')
				players[i]->battlePhase(NULL);
			else{
				cout<< "\nWhich Player do you want to battle?"<< endl<< "Suggested list:"<< endl;
				for(int j=0; j< players.size(); j++){
					if(i!= j)
						cout<< j+1<< ") "<< players[j]->name<< endl;
				}
				cout<< "Type a number from suggested list: ";
				int n= 0;
				while(n< 1 || n> players.size() || n-1== i){
					cin>> n;
					cout<< endl;
				}
				players[i]->battlePhase(players[n-1]);
			}
		}
		winner= checkWinningCondition();
		if(winner!= -1){
			cout<< "PLAYER "<< players[winner]->name<< " IS THE WINNER!"<< endl;
			break;
		}

		cout<< "\033[1;35mECONOMY PHASE\033[0m"<< endl;
		for(int i=0; i< players.size(); i++){
			if(players[i]->give_no_provinces()== 0)
				continue;
			players[i]->economyPhase();
		}

		cout<< "\033[1;35mFINAL PHASE\033[0m"<< endl;
		for(int i=0; i< players.size(); i++){
				if(players[i]->give_no_provinces()== 0)
				continue;
			players[i]->endingPhase();
		}

	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
movq 0x18a0b(%rip), %rdi     # 0x24fd0
leaq 0xc14f(%rip), %rsi      # 0x1871b
callq 0x4200
movq %rax, %rdi
movq 0x189e5(%rip), %rsi     # 0x24fc0
callq 0x4230
movl $0x0, -0x10(%rbp)
movq -0x38(%rbp), %rdi
movslq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
callq 0xcb70
movq %rax, %rcx
movq -0x40(%rbp), %rax
cmpq %rcx, %rax
jae 0xc640
movq -0x38(%rbp), %rdi
movslq -0x10(%rbp), %rsi
callq 0xcb90
movq (%rax), %rdi
callq 0xf850
cmpl $0x0, %eax
jne 0xc620
jmp 0xc635
movq -0x38(%rbp), %rdi
movslq -0x10(%rbp), %rsi
callq 0xcb90
movq (%rax), %rdi
callq 0xf950
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0xc5e7
movq 0x18989(%rip), %rdi     # 0x24fd0
leaq 0xc0e7(%rip), %rsi      # 0x18735
callq 0x4200
movq %rax, %rdi
movq 0x18963(%rip), %rsi     # 0x24fc0
callq 0x4230
movl $0x0, -0x14(%rbp)
movq -0x38(%rbp), %rdi
movslq -0x14(%rbp), %rax
movq %rax, -0x48(%rbp)
callq 0xcb70
movq %rax, %rcx
movq -0x48(%rbp), %rax
cmpq %rcx, %rax
jae 0xc6c2
movq -0x38(%rbp), %rdi
movslq -0x14(%rbp), %rsi
callq 0xcb90
movq (%rax), %rdi
callq 0xf850
cmpl $0x0, %eax
jne 0xc6a2
jmp 0xc6b7
movq -0x38(%rbp), %rdi
movslq -0x14(%rbp), %rsi
callq 0xcb90
movq (%rax), %rdi
callq 0xfef0
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xc669
movq 0x18907(%rip), %rdi     # 0x24fd0
leaq 0xc080(%rip), %rsi      # 0x18750
callq 0x4200
movq %rax, %rdi
movq 0x188e1(%rip), %rsi     # 0x24fc0
callq 0x4230
movl $0x0, -0x18(%rbp)
movq -0x38(%rbp), %rdi
movslq -0x18(%rbp), %rax
movq %rax, -0x50(%rbp)
callq 0xcb70
movq %rax, %rcx
movq -0x50(%rbp), %rax
cmpq %rcx, %rax
jae 0xc9e0
movq -0x38(%rbp), %rdi
movslq -0x18(%rbp), %rsi
callq 0xcb90
movq (%rax), %rdi
callq 0xf850
cmpl $0x0, %eax
jne 0xc72b
jmp 0xc9d2
movq 0x1889e(%rip), %rdi     # 0x24fd0
leaq 0xc02f(%rip), %rsi      # 0x18768
callq 0x4200
movq -0x38(%rbp), %rdi
movq %rax, -0x58(%rbp)
movslq -0x18(%rbp), %rsi
callq 0xcb90
movq -0x58(%rbp), %rdi
movq (%rax), %rsi
addq $0xa8, %rsi
callq 0x41d0
movq %rax, %rdi
leaq 0xc005(%rip), %rsi      # 0x18771
callq 0x4200
movq %rax, %rdi
movq 0x18845(%rip), %rsi     # 0x24fc0
callq 0x4230
movq 0x18849(%rip), %rdi     # 0x24fd0
leaq 0xbff0(%rip), %rsi      # 0x1877e
callq 0x4200
movq %rax, %rdi
movq 0x18823(%rip), %rsi     # 0x24fc0
callq 0x4230
movq %rax, %rdi
movq 0x18814(%rip), %rsi     # 0x24fc0
callq 0x4230
movq -0x38(%rbp), %rdi
movslq -0x18(%rbp), %rsi
callq 0xcb90
movq (%rax), %rdi
callq 0x10a90
testb $0x1, %al
jne 0xc800
movq 0x187ff(%rip), %rdi     # 0x24fd0
leaq 0xbfb7(%rip), %rsi      # 0x1878f
callq 0x4200
movq %rax, %rdi
movq 0x187d9(%rip), %rsi     # 0x24fc0
callq 0x4230
movq %rax, %rdi
movq 0x187ca(%rip), %rsi     # 0x24fc0
callq 0x4230
jmp 0xc9d2
movq 0x187c9(%rip), %rdi     # 0x24fd0
leaq 0xbfa4(%rip), %rsi      # 0x187b2
callq 0x4200
movq 0x187c6(%rip), %rdi     # 0x24fe0
leaq -0x19(%rbp), %rsi
callq 0x42b0
movsbl -0x19(%rbp), %eax
cmpl $0x44, %eax
jne 0xc84a
movq -0x38(%rbp), %rdi
movslq -0x18(%rbp), %rsi
callq 0xcb90
movq (%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x10b40
jmp 0xc9d0
movq 0x1877f(%rip), %rdi     # 0x24fd0
leaq 0xbf7a(%rip), %rsi      # 0x187d2
callq 0x4200
movq %rax, %rdi
movq 0x18759(%rip), %rsi     # 0x24fc0
callq 0x4230
movq %rax, %rdi
leaq 0xbf81(%rip), %rsi      # 0x187f7
callq 0x4200
movq %rax, %rdi
movq 0x1873b(%rip), %rsi     # 0x24fc0
callq 0x4230
movl $0x0, -0x20(%rbp)
movq -0x38(%rbp), %rdi
movslq -0x20(%rbp), %rax
movq %rax, -0x60(%rbp)
callq 0xcb70
movq %rax, %rcx
movq -0x60(%rbp), %rax
cmpq %rcx, %rax
jae 0xc91a
movl -0x18(%rbp), %eax
cmpl -0x20(%rbp), %eax
je 0xc90a
movl -0x20(%rbp), %esi
addl $0x1, %esi
movq 0x1870d(%rip), %rdi     # 0x24fd0
callq 0x4330
movq %rax, %rdi
leaq 0xbf35(%rip), %rsi      # 0x18807
callq 0x4200
movq -0x38(%rbp), %rdi
movq %rax, -0x68(%rbp)
movslq -0x20(%rbp), %rsi
callq 0xcb90
movq -0x68(%rbp), %rdi
movq (%rax), %rsi
addq $0xa8, %rsi
callq 0x41d0
movq %rax, %rdi
movq 0x186bb(%rip), %rsi     # 0x24fc0
callq 0x4230
jmp 0xc90c
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xc891
movq 0x186af(%rip), %rdi     # 0x24fd0
leaq 0xbee2(%rip), %rsi      # 0x1880a
callq 0x4200
movl $0x0, -0x24(%rbp)
movb $0x1, %al
cmpl $0x1, -0x24(%rbp)
movb %al, -0x69(%rbp)
jl 0xc970
movq -0x38(%rbp), %rdi
movslq -0x24(%rbp), %rax
movq %rax, -0x78(%rbp)
callq 0xcb70
movq -0x78(%rbp), %rcx
movq %rax, %rdx
movb $0x1, %al
cmpq %rdx, %rcx
movb %al, -0x69(%rbp)
ja 0xc970
movl -0x24(%rbp), %eax
subl $0x1, %eax
cmpl -0x18(%rbp), %eax
sete %al
movb %al, -0x69(%rbp)
movb -0x69(%rbp), %al
testb $0x1, %al
jne 0xc979
jmp 0xc99e
movq 0x18660(%rip), %rdi     # 0x24fe0
leaq -0x24(%rbp), %rsi
callq 0x4150
movq 0x18640(%rip), %rdi     # 0x24fd0
movq 0x18629(%rip), %rsi     # 0x24fc0
callq 0x4230
jmp 0xc934
movq -0x38(%rbp), %rdi
movslq -0x18(%rbp), %rsi
callq 0xcb90
movq -0x38(%rbp), %rdi
movq (%rax), %rax
movq %rax, -0x80(%rbp)
movl -0x24(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0xcb90
movq -0x80(%rbp), %rdi
movq (%rax), %rsi
callq 0x10b40
jmp 0xc9d2
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xc6eb
movq -0x38(%rbp), %rdi
callq 0xc500
movl %eax, -0xc(%rbp)
cmpl $-0x1, -0xc(%rbp)
je 0xca52
movq 0x185d7(%rip), %rdi     # 0x24fd0
leaq 0xbd0d(%rip), %rsi      # 0x1870d
callq 0x4200
movq -0x38(%rbp), %rdi
movq %rax, -0x88(%rbp)
movslq -0xc(%rbp), %rsi
callq 0xcb90
movq -0x88(%rbp), %rdi
movq (%rax), %rsi
addq $0xa8, %rsi
callq 0x41d0
movq %rax, %rdi
leaq 0xbdf5(%rip), %rsi      # 0x1882e
callq 0x4200
movq %rax, %rdi
movq 0x18578(%rip), %rsi     # 0x24fc0
callq 0x4230
jmp 0xcb67
movq 0x18577(%rip), %rdi     # 0x24fd0
leaq 0xbdde(%rip), %rsi      # 0x1883e
callq 0x4200
movq %rax, %rdi
movq 0x18551(%rip), %rsi     # 0x24fc0
callq 0x4230
movl $0x0, -0x28(%rbp)
movq -0x38(%rbp), %rdi
movslq -0x28(%rbp), %rax
movq %rax, -0x90(%rbp)
callq 0xcb70
movq %rax, %rcx
movq -0x90(%rbp), %rax
cmpq %rcx, %rax
jae 0xcada
movq -0x38(%rbp), %rdi
movslq -0x28(%rbp), %rsi
callq 0xcb90
movq (%rax), %rdi
callq 0xf850
cmpl $0x0, %eax
jne 0xcaba
jmp 0xcacf
movq -0x38(%rbp), %rdi
movslq -0x28(%rbp), %rsi
callq 0xcb90
movq (%rax), %rdi
callq 0x12610
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xca7b
movq 0x184ef(%rip), %rdi     # 0x24fd0
leaq 0xbd6f(%rip), %rsi      # 0x18857
callq 0x4200
movq %rax, %rdi
movq 0x184c9(%rip), %rsi     # 0x24fc0
callq 0x4230
movl $0x0, -0x2c(%rbp)
movq -0x38(%rbp), %rdi
movslq -0x2c(%rbp), %rax
movq %rax, -0x98(%rbp)
callq 0xcb70
movq %rax, %rcx
movq -0x98(%rbp), %rax
cmpq %rcx, %rax
jae 0xcb62
movq -0x38(%rbp), %rdi
movslq -0x2c(%rbp), %rsi
callq 0xcb90
movq (%rax), %rdi
callq 0xf850
cmpl $0x0, %eax
jne 0xcb42
jmp 0xcb57
movq -0x38(%rbp), %rdi
movslq -0x2c(%rbp), %rsi
callq 0xcb90
movq (%rax), %rdi
callq 0x13100
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xcb03
jmp 0xc5be
addq $0xa0, %rsp
popq %rbp
retq