// File: /workspace/github_cpp_makefile_star2_O1/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 0xb023(%rip), %r14      # 0x11fd0
leaq 0x58d3(%rip), %rbp      # 0xc887
movq 0xb025(%rip), %r13      # 0x11fe0
movl $0x19, %edx
movq %r14, %rdi
leaq 0x5870(%rip), %rsi      # 0xc83a
callq 0x31a0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq (%rbx), %rax
cmpq %rax, 0x8(%rbx)
je 0x7031
xorl %r15d, %r15d
movq (%rax,%r15,8), %rdi
callq 0x8246
testl %eax, %eax
je 0x701b
movq (%rbx), %rax
movq (%rax,%r15,8), %rdi
callq 0x835e
incq %r15
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r15, %rcx
ja 0x7002
movl $0x1a, %edx
movq %r14, %rdi
leaq 0x5814(%rip), %rsi      # 0xc854
callq 0x31a0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq (%rbx), %rax
cmpq %rax, 0x8(%rbx)
je 0x70a7
xorl %r15d, %r15d
movq (%rax,%r15,8), %rdi
callq 0x8246
testl %eax, %eax
je 0x7091
movq (%rbx), %rax
movq (%rax,%r15,8), %rdi
callq 0x8908
incq %r15
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r15, %rcx
ja 0x7078
movl $0x17, %edx
movq %r14, %rdi
leaq 0x57b9(%rip), %rsi      # 0xc86f
callq 0x31a0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq (%rbx), %rax
cmpq %rax, 0x8(%rbx)
je 0x7440
xorl %r15d, %r15d
movq (%rax,%r15,8), %rdi
callq 0x8246
testl %eax, %eax
je 0x7426
movl $0x8, %edx
movq %r14, %rdi
movq %rbp, %rsi
callq 0x31a0
movq (%rbx), %rax
movq (%rax,%r15,8), %rax
movq 0xa8(%rax), %rsi
movq 0xb0(%rax), %rdx
movq %r14, %rdi
callq 0x31a0
movq %rax, %r12
movl $0xc, %edx
movq %rax, %rdi
leaq 0x574e(%rip), %rsi      # 0xc890
callq 0x31a0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movl $0x10, %edx
movq %r14, %rdi
leaq 0x571f(%rip), %rsi      # 0xc89d
callq 0x31a0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq (%rbx), %rax
movq (%rax,%r15,8), %rdi
callq 0x949e
testb %al, %al
je 0x721a
movl $0x1f, %edx
movq %r14, %rdi
leaq 0x56de(%rip), %rsi      # 0xc8d1
callq 0x31a0
movq %r13, %rdi
leaq 0x3(%rsp), %rsi
callq 0x31c0
cmpb $0x44, 0x3(%rsp)
jne 0x7284
movq (%rbx), %rax
movq (%rax,%r15,8), %rdi
xorl %esi, %esi
jmp 0x7421
movl $0x22, %edx
movq %r14, %rdi
leaq 0x5685(%rip), %rsi      # 0xc8ae
callq 0x31a0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
jmp 0x7426
movl $0x24, %edx
movq %r14, %rdi
leaq 0x565e(%rip), %rsi      # 0xc8f1
callq 0x31a0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq %rax, %r12
movl $0xf, %edx
movq %rax, %rdi
leaq 0x5645(%rip), %rsi      # 0xc916
callq 0x31a0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq 0x8(%rbx), %rax
cmpq (%rbx), %rax
leaq 0x4(%rsp), %r12
je 0x739c
xorl %ebp, %ebp
cmpq %rbp, %r15
je 0x7385
leal 0x1(%rbp), %esi
movq %r14, %rdi
callq 0x3200
movq %rax, %r12
movl $0x2, %edx
movq %rax, %rdi
leaq 0x55f2(%rip), %rsi      # 0xc926
callq 0x31a0
movq (%rbx), %rax
movq (%rax,%rbp,8), %rax
movq 0xa8(%rax), %rsi
movq 0xb0(%rax), %rdx
movq %r12, %rdi
callq 0x31a0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r12, %rdi
leaq 0x4(%rsp), %r12
callq 0x3030
movq %rax, %rdi
callq 0x30f0
incq %rbp
movq 0x8(%rbx), %rax
subq (%rbx), %rax
sarq $0x3, %rax
cmpq %rbp, %rax
ja 0x7312
movl $0x23, %edx
movq %r14, %rdi
leaq 0x557e(%rip), %rsi      # 0xc929
callq 0x31a0
movl $0x0, 0x4(%rsp)
leaq 0x54c8(%rip), %rbp      # 0xc887
movslq 0x4(%rsp), %rax
testq %rax, %rax
jle 0x73e3
movq (%rbx), %rcx
movq 0x8(%rbx), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
cmpq %rax, %rdx
jb 0x73e3
decl %eax
cmpq %rax, %r15
jne 0x7417
movq %r13, %rdi
movq %r12, %rsi
callq 0x30d0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
jmp 0x73bf
movq (%rcx,%r15,8), %rdi
cltq
movq (%rcx,%rax,8), %rsi
callq 0x94cc
incq %r15
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r15, %rcx
ja 0x70f2
movq %rbx, %rdi
callq 0x6f32
cmpl $-0x1, %eax
jne 0x7546
movl $0x18, %edx
movq %r14, %rdi
leaq 0x54fd(%rip), %rsi      # 0xc95d
callq 0x31a0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq (%rbx), %rax
cmpq %rax, 0x8(%rbx)
je 0x74c7
xorl %r15d, %r15d
movq (%rax,%r15,8), %rdi
callq 0x8246
testl %eax, %eax
je 0x74b1
movq (%rbx), %rax
movq (%rax,%r15,8), %rdi
callq 0xa86a
incq %r15
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r15, %rcx
ja 0x7498
movl $0x16, %edx
movq %r14, %rdi
leaq 0x54a0(%rip), %rsi      # 0xc976
callq 0x31a0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq (%rbx), %rax
cmpq %rax, 0x8(%rbx)
je 0x6fbb
xorl %r15d, %r15d
movq (%rax,%r15,8), %rdi
callq 0x8246
testl %eax, %eax
je 0x752b
movq (%rbx), %rax
movq (%rax,%r15,8), %rdi
callq 0xb282
incq %r15
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r15, %rcx
ja 0x7512
jmp 0x6fbb
movl %eax, %r12d
movq 0xaa80(%rip), %r14      # 0x11fd0
leaq 0x52d5(%rip), %rsi      # 0xc82c
movl $0x7, %edx
movq %r14, %rdi
callq 0x31a0
movslq %r12d, %rax
movq (%rbx), %rcx
movq (%rcx,%rax,8), %rax
movq 0xa8(%rax), %rsi
movq 0xb0(%rax), %rdx
movq %r14, %rdi
callq 0x31a0
movq %rax, %rbx
leaq 0x53bf(%rip), %rsi      # 0xc94d
movl $0xf, %edx
movq %rax, %rdi
callq 0x31a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop