64 lines
2.7 KiB
C++
64 lines
2.7 KiB
C++
#include "gameplay.h"
|
|
|
|
Gameplay::Gameplay() {};
|
|
|
|
Gameplay::~Gameplay() {};
|
|
|
|
int Gameplay::randomFirst(char c1, char c2, int rows, int cols, RandomPlayer r_player, StrategicPlayer s_player, Board* board, Points* stepList, Scores* scoreList, Points* temp) {
|
|
point move = r_player.randomMove(*temp);
|
|
move.player = c1;
|
|
cout<<move.player<<" "<<move.x<<" "<<move.y<<endl;
|
|
stepList->push(move);
|
|
board->updateBoard(move.player, move.x, move.y);
|
|
bool newTurn = board->evenRowBoxComplete(move, *scoreList, 2*rows-1, 2*cols-1) || board->oddRowBoxComplete(move, *scoreList, 2*rows-1, 2*cols-1);
|
|
if(newTurn) {
|
|
randomFirst(c1, c2, rows, cols, r_player, s_player, board, stepList, scoreList, temp);
|
|
}
|
|
|
|
if (temp->getSize()==0) {
|
|
cout<<"END"<<endl;
|
|
return 0;
|
|
} else {
|
|
point move = s_player.strategicMove(*board, *temp);
|
|
move.player = c2;
|
|
cout<<move.player<<" "<<move.x<<" "<<move.y<<endl;
|
|
stepList->push(move);
|
|
board->updateBoard(move.player, move.x, move.y);
|
|
newTurn = board->evenRowBoxComplete(move, *scoreList, 2*rows-1, 2*cols-1) || board->oddRowBoxComplete(move, *scoreList, 2*rows-1, 2*cols-1);
|
|
if (newTurn) {
|
|
strategicFirst(c1, c2, rows, cols, r_player, s_player, board, stepList, scoreList, temp);
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int Gameplay::strategicFirst(char c1, char c2, int rows, int cols, RandomPlayer r_player, StrategicPlayer s_player, Board* board, Points* stepList, Scores* scoreList, Points* temp) {
|
|
point move = s_player.strategicMove(*board, *temp);
|
|
move.player = c1;
|
|
cout<<move.player<<" "<<move.x<<" "<<move.y<<endl;
|
|
stepList->push(move);
|
|
board->updateBoard(move.player, move.x, move.y);
|
|
bool newTurn = board->evenRowBoxComplete(move, *scoreList, 2*rows-1, 2*cols-1) || board->oddRowBoxComplete(move, *scoreList, 2*rows-1, 2*cols-1);
|
|
if (newTurn) {
|
|
strategicFirst(c1, c2, rows, cols, r_player, s_player, board, stepList, scoreList, temp);
|
|
}
|
|
|
|
if (temp->getSize()==0) {
|
|
cout<<"END"<<endl;
|
|
return 0;
|
|
} else {
|
|
point move = r_player.randomMove(*temp);
|
|
move.player = c2;
|
|
cout<<move.player<<" "<<move.x<<" "<<move.y<<endl;
|
|
stepList->push(move);
|
|
board->updateBoard(move.player, move.x, move.y);
|
|
board->evenRowBoxComplete(move, *scoreList, 2*rows-1, 2*cols-1);
|
|
board->oddRowBoxComplete(move, *scoreList, 2*rows-1, 2*cols-1);
|
|
newTurn = board->evenRowBoxComplete(move, *scoreList, 2*rows-1, 2*cols-1) || board->oddRowBoxComplete(move, *scoreList, 2*rows-1, 2*cols-1);
|
|
if (newTurn) {
|
|
randomFirst(c1, c2, rows, cols, r_player, s_player, board, stepList, scoreList, temp);
|
|
}
|
|
}
|
|
return 0;
|
|
}
|