Commit 11d86453 authored by Jason Riggs's avatar Jason Riggs

change

parent a666f285
......@@ -6,21 +6,21 @@
using namespace std;
pair<int, int> AIplayer::move1() {
pair<int, int> AIplayer::move1(displayBoard AImove) {
// declare variables
displayBoard AImove;
int tempRow, tempCol, x = 0, y = 0;
int x = 0, y = 0;
pair<int, int> AIpair;
// loop until valid move is found
for (int row = 0; row < 8; ++row) {
for (int col = 0; col < 8; ++col) {
tempRow = row;
tempCol = col;
if (AImove.isValidAdjacent(tempRow, tempCol, 'X') && AImove.isValidFlip(tempRow, tempCol, 'O')) {
x = tempRow;
y = tempCol;
bool flag1 = AImove.isValidAdjacent(row, col, 'X');
bool flag2 = AImove.isValidFlip(row, col, 'O');
cout << row << " " << col << " " << flag1 << " " << flag2<<endl;
if (AImove.isValidAdjacent(row, col, 'X') && AImove.isValidFlip(row, col, 'O')) {
x = row;
y = col;
}
}
}
......
#include <cstdlib>
#include <utility>
#include "Board.h"
using namespace std;
class Error;
class displayBoard;
class AIplayer {
public:
AIplayer() { srand(0); } // basic constructor to seed random number generator
AIplayer(int seed) { srand(seed); } // constructor to seed random number generator with desired seed
pair<int, int> move1(); // easy move
pair<int, int> move1(displayBoard board); // easy move
pair<int, int> move2(); // hard move mutator
private: // not used
......
......@@ -6,6 +6,7 @@ using namespace std;
// Place starting pieces
void displayBoard::start() {
// The rest of the board has random data in it possible including X and O
board[4-1][4-1] = {'X'};
board[5-1][4-1] = {'O'};
board[5-1][5-1] = {'X'};
......@@ -396,29 +397,33 @@ void displayBoard::uprightCheck(int x,int y,char chip, bool change) { // functi
// Checks to see if there is an opponents piece around the placed piece
bool displayBoard::isValidAdjacent(int row, int col, char oppTurn) {
if (board[row + 1][col] == oppTurn) {
bool displayBoard::isValidAdjacent(int x, int y, char oppTurn) {
if(y == 2){
cout << "displayBoard::isValidAdjacent(" << x << "," << y << "," << (char)oppTurn<< ")";
cout << " where (4,2) is \'"<< (char)board[4][2] << "\' (" << (int)board[4][2] << ")" << endl;
}
if (board[x + 1][y] == oppTurn) {
return true;
}
else if (board[row - 1][col] == oppTurn) {
else if (board[x - 1][y] == oppTurn) {
return true;
}
else if (board[row][col + 1] == oppTurn) {
else if (board[x][y + 1] == oppTurn) {
return true;
}
else if (board[row][col - 1] == oppTurn) {
else if (board[x][y - 1] == oppTurn) {
return true;
}
else if (board[row - 1][col - 1] == oppTurn) {
else if (board[x - 1][y - 1] == oppTurn) {
return true;
}
else if (board[row - 1][col + 1] == oppTurn) {
else if (board[x - 1][y + 1] == oppTurn) {
return true;
}
else if (board[row + 1][col - 1] == oppTurn) {
else if (board[x + 1][y - 1] == oppTurn) {
return true;
}
else if (board[row + 1][col + 1] == oppTurn) {
else if (board[x + 1][y + 1] == oppTurn) {
return true;
}
return false;
......
#ifndef BOARD_H
#define BOARD_H
#include <iostream>
#include <vector>
using namespace std;
class displayBoard {
......@@ -38,3 +38,4 @@ class displayBoard {
};
#endif
\ No newline at end of file
......@@ -9,7 +9,7 @@ int main() {
int seed = 0;
int turn = 1;
int difficulty = 0;
int x,y;
int x, y;
int aiX, aiY;
pair<int, int> AImove;
bool winner = false;
......@@ -52,7 +52,7 @@ int main() {
}
// start the game
displayBoard board;
displayBoard board;// Brand new board
board.start();
board.printBoard();
cout << "X goes first."<<endl;
......@@ -93,10 +93,12 @@ int main() {
// Player two's Move
} else if (turn == 2) {
AImove = AIturn.move1();
AImove = AIturn.move1(board);
cout << AImove.first << " " << AImove.second << endl;
// Check fo valid move
// if(board.isValidAdjacent(aiX, aiY, 'X') && board.isValidFlip(aiX, aiY, 'O')){
aiX = AImove.first;
aiY = AImove.second;
//Check fo valid move
// if(board.isValidAdjacent(aiX-1, aiY-1, 'X') && board.isValidFlip(aiX-1, aiY-1, 'O')){
// // Player moves
// board.playerMove2(aiX,aiY);
// // Check for flips in every direction
......@@ -110,7 +112,7 @@ int main() {
// board.downrightCheck(aiX,aiY,'O', true);
// board.downleftCheck(aiX,aiY,'O', true);
// Change to player 1
//Change to player 1
turn--;
// }else{
......@@ -161,29 +163,31 @@ int main() {
} else if (turn == 2) {
AImove = AIturn.move2();
cout << AImove.first << " " << AImove.second << endl;
aiX = AImove.first;
aiY = AImove.second;
// Check fo valid move
// if(board.isValidAdjacent(aiX, aiY, 'X') && board.isValidFlip(aiX, aiY, 'O')){
// // Player moves
// board.playerMove2(aiX,aiY);
// // Check for flips in every direction
// board.upCheck(aiX,aiY, 'O', true);
// board.downCheck(aiX,aiY, 'O', true);
// board.leftCheck(aiX,aiY, 'O', true);
// board.rightCheck(aiX,aiY, 'O', true);
if(board.isValidAdjacent(aiX-1, aiY-1, 'X') && board.isValidFlip(aiX-1, aiY-1, 'O')){
// Player moves
board.playerMove2(aiX,aiY);
// Check for flips in every direction
board.upCheck(aiX,aiY, 'O', true);
board.downCheck(aiX,aiY, 'O', true);
board.leftCheck(aiX,aiY, 'O', true);
board.rightCheck(aiX,aiY, 'O', true);
// board.uprightCheck(aiX,aiY,'O', true);
// board.upleftCheck(aiX,aiY,'O', true);
// board.downrightCheck(aiX,aiY,'O', true);
// board.downleftCheck(aiX,aiY,'O', true);
board.uprightCheck(aiX,aiY,'O', true);
board.upleftCheck(aiX,aiY,'O', true);
board.downrightCheck(aiX,aiY,'O', true);
board.downleftCheck(aiX,aiY,'O', true);
// Change to player 1
turn--;
// }else{
// // Prints invalid and then asks for another move
// cout << "Invalid Move!"<<endl;
}else{
// Prints invalid and then asks for another move
cout << "Invalid Move!"<<endl;
// }
}
}
board.printBoard();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment