// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0xaf31(%rip), %r14      # 0x10fd0
leaq 0x47cd(%rip), %rbp      # 0xa873
movq 0xaf33(%rip), %r13      # 0x10fe0
movq %r14, %rdi
leaq 0x476f(%rip), %rsi      # 0xa826
callq 0x31a0
movq %rax, %rdi
callq 0x30d0
xorl %r15d, %r15d
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r15, %rcx
jbe 0x60f8
movq (%rax,%r15,8), %rdi
callq 0x6f9e
testl %eax, %eax
je 0x60f3
movq (%rbx), %rax
movq (%rax,%r15,8), %rdi
callq 0x7042
incq %r15
jmp 0x60c7
movq %r14, %rdi
leaq 0x473e(%rip), %rsi      # 0xa840
callq 0x31a0
movq %rax, %rdi
callq 0x30d0
xorl %r15d, %r15d
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r15, %rcx
jbe 0x6143
movq (%rax,%r15,8), %rdi
callq 0x6f9e
testl %eax, %eax
je 0x613e
movq (%rbx), %rax
movq (%rax,%r15,8), %rdi
callq 0x7328
incq %r15
jmp 0x6112
movq %r14, %rdi
leaq 0x470e(%rip), %rsi      # 0xa85b
callq 0x31a0
movq %rax, %rdi
callq 0x30d0
xorl %r12d, %r12d
movl $0xa8, %r15d
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r12, %rcx
jbe 0x6335
movq (%rax,%r12,8), %rdi
callq 0x6f9e
testl %eax, %eax
je 0x632d
movq %r14, %rdi
movq %rbp, %rsi
callq 0x31a0
movq (%rbx), %rcx
movq (%rcx,%r12,8), %rsi
addq %r15, %rsi
movq %rax, %rdi
callq 0x3170
movq %rax, %rdi
leaq 0x46ca(%rip), %rsi      # 0xa87c
callq 0x31a0
movq %rax, %rdi
callq 0x30d0
movq %r14, %rdi
leaq 0x46c0(%rip), %rsi      # 0xa889
callq 0x31a0
movq %rax, %rdi
callq 0x30d0
movq %rax, %rdi
callq 0x30d0
movq (%rbx), %rax
movq (%rax,%r12,8), %rdi
callq 0x7a36
movq %r14, %rdi
testb %al, %al
je 0x621f
leaq 0x46c5(%rip), %rsi      # 0xa8bd
callq 0x31a0
movq %r13, %rdi
leaq 0x3(%rsp), %rsi
callq 0x31f0
cmpb $0x44, 0x3(%rsp)
jne 0x6240
movq (%rbx), %rax
movq (%rax,%r12,8), %rdi
xorl %esi, %esi
jmp 0x6328
leaq 0x4674(%rip), %rsi      # 0xa89a
callq 0x31a0
movq %rax, %rdi
callq 0x30d0
movq %rax, %rdi
callq 0x30d0
jmp 0x632d
movq %r14, %rdi
leaq 0x4693(%rip), %rsi      # 0xa8dd
callq 0x31a0
movq %rax, %rdi
callq 0x30d0
movq %rax, %rdi
leaq 0x46a1(%rip), %rsi      # 0xa902
callq 0x31a0
leaq 0x1(%r12), %rbp
xorl %r15d, %r15d
movq %rax, %rdi
callq 0x30d0
movq 0x8(%rbx), %rax
subq (%rbx), %rax
sarq $0x3, %rax
cmpq %r15, %rax
jbe 0x62c2
incq %r15
cmpq %r15, %rbp
je 0x6281
movq %r14, %rdi
movl %r15d, %esi
callq 0x3240
movq %rax, %rdi
leaq 0x466f(%rip), %rsi      # 0xa912
callq 0x31a0
movq (%rbx), %rcx
movq -0x8(%rcx,%r15,8), %rsi
movl $0xa8, %ecx
addq %rcx, %rsi
movq %rax, %rdi
callq 0x3170
jmp 0x626e
movq %r14, %rdi
leaq 0x4649(%rip), %rsi      # 0xa915
callq 0x31a0
andl $0x0, 0x4(%rsp)
xorl %eax, %eax
leaq 0x4594(%rip), %rbp      # 0xa873
movl $0xa8, %r15d
testl %eax, %eax
jle 0x6305
movl %eax, %edx
movq (%rbx), %rcx
movq 0x8(%rbx), %rsi
subq %rcx, %rsi
sarq $0x3, %rsi
cmpq %rdx, %rsi
jb 0x6305
decl %eax
cmpq %rax, %r12
jne 0x6320
movq %r13, %rdi
leaq 0x4(%rsp), %rsi
callq 0x3110
movq %r14, %rdi
callq 0x30d0
movl 0x4(%rsp), %eax
jmp 0x62e5
movq (%rcx,%r12,8), %rdi
movq (%rcx,%rax,8), %rsi
callq 0x7a62
incq %r12
jmp 0x6163
movq %rbx, %rdi
callq 0x6034
cmpl $-0x1, %eax
jne 0x63e0
movq %r14, %rdi
leaq 0x45f9(%rip), %rsi      # 0xa949
callq 0x31a0
movq %rax, %rdi
callq 0x30d0
xorl %r15d, %r15d
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r15, %rcx
jbe 0x6391
movq (%rax,%r15,8), %rdi
callq 0x6f9e
testl %eax, %eax
je 0x638c
movq (%rbx), %rax
movq (%rax,%r15,8), %rdi
callq 0x85ca
incq %r15
jmp 0x6360
movq %r14, %rdi
leaq 0x45c7(%rip), %rsi      # 0xa962
callq 0x31a0
movq %rax, %rdi
callq 0x30d0
xorl %r15d, %r15d
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r15, %rcx
jbe 0x60ad
movq (%rax,%r15,8), %rdi
callq 0x6f9e
testl %eax, %eax
je 0x63db
movq (%rbx), %rax
movq (%rax,%r15,8), %rdi
callq 0x8c28
incq %r15
jmp 0x63ab
movl %eax, %r15d
movq 0xabe6(%rip), %rdi      # 0x10fd0
leaq 0x4427(%rip), %rsi      # 0xa818
callq 0x31a0
movslq %r15d, %rcx
movq (%rbx), %rdx
movl $0xa8, %esi
addq (%rdx,%rcx,8), %rsi
movq %rax, %rdi
callq 0x3170
leaq 0x4525(%rip), %rsi      # 0xa939
movq %rax, %rdi
callq 0x31a0
movq %rax, %rdi
callq 0x30d0
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop