2015-10-07 16:43:09 -05:00
|
|
|
#include <iostream>
|
|
|
|
#include <vector>
|
2015-10-12 17:11:58 -05:00
|
|
|
#include <stdlib.h>
|
2015-10-07 16:43:09 -05:00
|
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2015-10-12 17:11:58 -05:00
|
|
|
class piece
|
2015-10-07 16:43:09 -05:00
|
|
|
{
|
2015-10-12 17:11:58 -05:00
|
|
|
char color; //w for white, b for white, e for empty
|
|
|
|
int xpos;
|
|
|
|
int ypos;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
piece(int x, int y)
|
|
|
|
{
|
|
|
|
xpos = x;
|
|
|
|
ypos = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setColor(char kolor)
|
|
|
|
{
|
|
|
|
color = kolor;
|
|
|
|
}
|
|
|
|
|
|
|
|
char getColor()
|
|
|
|
{
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct moves
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
string moveType;
|
|
|
|
|
|
|
|
moves(int _x, int _y, string m)
|
|
|
|
{
|
|
|
|
x = _x;
|
|
|
|
y = _y;
|
|
|
|
moveType = m;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class Board
|
|
|
|
{
|
|
|
|
char boardArray [8][8];
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
Board()
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 2; ++i)
|
|
|
|
{
|
|
|
|
for (int j = 0; j < 8; ++j)
|
|
|
|
{
|
|
|
|
boardArray[i][j] = 'X';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 2; i < 6; ++i)
|
|
|
|
{
|
|
|
|
for (int j = 0; j < 8; ++j)
|
|
|
|
{
|
|
|
|
boardArray[i][j] = '_';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 6; i <= 7; ++i)
|
|
|
|
{
|
|
|
|
for (int j = 0; j < 8; ++j)
|
|
|
|
{
|
|
|
|
boardArray[i][j] = 'O';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void displayBoard()
|
|
|
|
{
|
|
|
|
cout<<"\n\n";
|
|
|
|
for (int i = 0; i < 8; ++i)
|
|
|
|
{
|
|
|
|
for (int j = 0; j < 8; ++j)
|
|
|
|
{
|
|
|
|
cout<<boardArray[i][j]<<" ";
|
|
|
|
}
|
|
|
|
cout<<endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void move(int x, int y, string moveType)
|
|
|
|
{
|
|
|
|
// if (moveType != "front" || moveType != "leftFront" || moveType != "rightFront")
|
|
|
|
// {
|
|
|
|
// cout<<"ERROR! invalid moveType!"<<endl;
|
|
|
|
// }
|
|
|
|
|
|
|
|
if (x > 8 || x < 0 || y > 8 || y < 0)
|
|
|
|
{
|
|
|
|
cout<<"ERROR: index out of bound!"<<endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
int temp = boardArray[x][y];
|
|
|
|
|
2015-10-12 17:19:29 -05:00
|
|
|
else if (temp == '_')
|
2015-10-12 17:11:58 -05:00
|
|
|
{
|
|
|
|
cout<<"there's no piece in that spot you dumbass!"<<endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
else if (temp == 'X' || temp == 'O')
|
|
|
|
{
|
|
|
|
if (moveType == "front")
|
|
|
|
{
|
|
|
|
if(boardArray[x+1][y] != '_')
|
|
|
|
{
|
|
|
|
cout<<"you can't move that piece forward"<<endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
boardArray[x][y] = '_';
|
|
|
|
boardArray[x+1][y] = temp;
|
|
|
|
|
|
|
|
displayBoard();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (moveType == "leftFront")
|
|
|
|
{
|
|
|
|
if (y == 0)
|
|
|
|
{
|
|
|
|
cout<<"you went out of the table you idiot!"<<endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
boardArray[x][y] = '_';
|
|
|
|
boardArray[x+1][y-1] = temp;
|
|
|
|
|
|
|
|
displayBoard();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (moveType == "rightFront")
|
|
|
|
{
|
|
|
|
if (y == 7)
|
|
|
|
{
|
|
|
|
cout<<"you went out of the table you idiot!"<<endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
boardArray[x][y] = '_';
|
|
|
|
boardArray[x+1][y-1] = temp;
|
|
|
|
|
|
|
|
displayBoard();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cout<<"wat?"<<endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cout<<"wat?"<<endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<moves> viewPossibleMoves()
|
|
|
|
{
|
|
|
|
cout<<"not yet!"<<endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void dumbassAI()
|
|
|
|
{
|
|
|
|
/*ai brain:
|
|
|
|
1) see all possible movements
|
|
|
|
2) pick a movement
|
|
|
|
3) execute movement
|
|
|
|
*/
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isGameOver()
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 8; ++i)
|
|
|
|
{
|
|
|
|
if (boardArray[0][i] == 'O')
|
|
|
|
{
|
|
|
|
cout<<"player O wins!"<<endl;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (boardArray[7][i] == 'X')
|
|
|
|
{
|
|
|
|
cout<<"player X wins!"<<endl;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-07 16:43:09 -05:00
|
|
|
};
|
|
|
|
|
2015-10-12 17:11:58 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-10-07 16:43:09 -05:00
|
|
|
int main()
|
|
|
|
{
|
2015-10-12 17:11:58 -05:00
|
|
|
Board b;
|
|
|
|
b.displayBoard();
|
|
|
|
|
|
|
|
int x,y;
|
|
|
|
string move;
|
|
|
|
|
|
|
|
while (!b.isGameOver())
|
|
|
|
{
|
|
|
|
cout<<"x: ";
|
|
|
|
cin>>x;
|
|
|
|
|
|
|
|
cout<<"y: ";
|
|
|
|
cin>>y;
|
|
|
|
|
|
|
|
cout<<"moveType: ";
|
|
|
|
cin>>move;
|
|
|
|
|
|
|
|
b.move(x,y,move);
|
|
|
|
}
|
2015-10-07 16:43:09 -05:00
|
|
|
|
|
|
|
}
|