Update main.cpp
This commit is contained in:
parent
200e216c6a
commit
b6c6d31f09
1 changed files with 229 additions and 2 deletions
231
main.cpp
231
main.cpp
|
@ -1,15 +1,242 @@
|
|||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
class board
|
||||
class piece
|
||||
{
|
||||
vector<vector<bool> > board;
|
||||
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];
|
||||
|
||||
if (temp == '_')
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue