I wrote this program back in high school 10 years ago and I found it today. I'm getting back into programming and I'd like to get it working again, some of the headers are deprecated which I tried to fix, and I was using borland c++ and now have Dev C++ so the graphics file I was using wasn't included but I think I have fixed that. However, there are still many other errors, mostly header and declaration oriented. I know this program worked before so I think it just needs updating for new standards. Any help would be much appreciated. Here is the code:
using namespace std ;
#include <iostream>
#include <iomanip>
#include <graphics.h>
#include <conio.h>
#include "apstring.inc"
#include <ctype>
#include <dos>
class Othello
{
private:
int key;
int centerx, centery, topy, bottomy, rightx, dist;
int sqsize, radius;
int highlightx, highlighty, selectx, selecty, checkx, checky;
int farx, fary;
int blackcount, whitecount;
char array[7][7], done;
int a, b, a1, b1, f, f1, wrongmove;
int numsq;
int count, tcount;
bool valid;
apstring play1, play2; //play1 will be the black chips
char direction; //play2 will be the white chips
public:
Othello();
name();
gameboard();
blackmove();
whitemove();
arrayidentity();
play();
winner();
};
int main()
{
clrscr();
Othello O;
getch();
O.name();
O.gameboard();
O.play();
getch();
return 0;
}
Othello::Othello()
{
//setgraphics mode
int graphdriver = DETECT, graphmode;
initgraph(&graphdriver, &graphmode, "c:..\\bgi");
//set background color
setbkcolor(BLUE);
settextstyle(TRIPLEX_FONT, HORIZ_DIR, 8);
outtextxy(170, 145, "Othello");
for (int x = 100; x <=200; x = x + 30)
{
delay(1000);
line(x, 300, x + 20, 300);
line(605 - x, 300, 605 - x - 20, 300);
}
setcolor(WHITE);
arc(300, 150, 240, 300, 120);
arc(300, 450, 60, 120, 120);
circle(150, 300, 100);
setcolor(BLUE);
arc(150, 300, 28, 331, 100);
setcolor(WHITE);
arc(450, 300, 152, 208, 100);
setfillstyle(SOLID_FILL, WHITE);
floodfill(300, 300, WHITE);
setcolor(DARKGRAY);
setfillstyle(SOLID_FILL, DARKGRAY);
circle(300, 300, 25);
floodfill(300, 300, DARKGRAY);
}
Othello::name()
{
setbkcolor(BLUE);
settextstyle(DEFAULT_FONT, HORIZ_DIR, 1);
cleardevice();
cout << endl << endl << endl << endl << endl;
cout << setw(50) << "Player 1, please enter your name: ";
getline(cin, play1);
cout << endl;
cout << setw(50) << "Player 2, please enter your name: ";
getline(cin, play2);
cout << endl << endl;
gotoxy(20, 10);
cout << play1 << " will be the black chips." << endl;
gotoxy(20, 11);
cout << play2 << " will be the white chips." << endl;
cout << endl << endl;
cout << setw(50) << "Press <Enter> to begin your game. " << endl;
getch();
setbkcolor(BLACK);
cleardevice();
}
Othello::gameboard() //draws the opening game board
{
centerx = 320;
centery = 240;
sqsize = 50;
radius = 15;
numsq = 3; //number of squares from center
//setting line color
setcolor(LIGHTGREEN);
//drawing perimeter
rectangle((centerx - numsq*sqsize), (centery - numsq*sqsize),
(centerx + numsq*sqsize), (centery +numsq*sqsize));
//setting background gameboard color
setfillstyle(SOLID_FILL, GREEN);
floodfill(centerx, centery, LIGHTGREEN);
//drawing center verticle line from top to bottom
line(centerx, (centery - numsq * sqsize), centerx, (centery + numsq* sqsize));
//drawing center horizontal line from left to right
line((centerx - numsq *sqsize), centery, (centerx + numsq*sqsize), centery);
//draw first horizontal line below top line of rectangle
line((centerx -numsq*sqsize), (centery - 2*sqsize),
(centerx + numsq*sqsize), (centery - 2*sqsize));
//draw second horizontal line below top line of rectangle
line((centerx -numsq*sqsize), (centery - sqsize),
(centerx + numsq*sqsize), (centery - sqsize));
//draw line below center horizontal line
line((centerx -numsq*sqsize), (centery + sqsize),
(centerx + numsq*sqsize), (centery + sqsize));
//draw line above bottom perimeter line
line((centerx -3*sqsize), (centery + 2*sqsize),
(centerx + 3*sqsize), (centery + 2*sqsize));
//VERITCLE LINES
//farthest left verticle line
line ((centerx - 2*sqsize), (centery + 3*sqsize),
(centerx - 2*sqsize), (centery - 3*sqsize));
//next line to the right
line ((centerx - sqsize), (centery + 3*sqsize),
(centerx - sqsize), (centery - 3*sqsize));
//first v line right of the center
line ((centerx + sqsize), (centery + 3*sqsize),
(centerx + sqsize), (centery - 3*sqsize));
//farthest right v line
line ((centerx + 2*sqsize), (centery + 3*sqsize),
(centerx + 2*sqsize), (centery - 3*sqsize));
//set array to all 'g'
for (a = 1; a <=6 ; ++ a)
{
for (b = 1; b <= 6; ++b)
array[a][b] = 'g';
}
//adding starting chips
//white chips
setcolor(LIGHTGREEN);
setfillstyle(SOLID_FILL, WHITE);
circle(centerx - sqsize/2, centery - sqsize/2, radius); //top white chip
//set corresponding array letter
array[3][3] = 'w';
circle(centerx + sqsize/2, centery + sqsize/2, radius); //bottom white chip
//set corresponding array letter
array[4][4] = 'w';
floodfill(centerx - sqsize/2, centery - sqsize/2, LIGHTGREEN); //filling white chips
floodfill(centerx +sqsize/2, centery +sqsize/2, LIGHTGREEN);
//black chips
setcolor(LIGHTGREEN);
setfillstyle(SOLID_FILL, BLACK);
circle(centerx + sqsize/2, centery - sqsize/2, radius); //top black chip
circle(centerx - sqsize/2, centery + sqsize/2, radius);
floodfill(centerx + sqsize/2, centery - sqsize/2, LIGHTGREEN); //filling black chips
floodfill(centerx - sqsize/2, centery + sqsize/2, LIGHTGREEN);
//set arrays for black chips
array[3][4] = 'b';
array[4][3] = 'b';
}
Othello::blackmove()
{
//beginning highlighted square
setfillstyle(SOLID_FILL, BLUE);
highlightx = centerx + sqsize - 2;
highlighty = centery - sqsize +2;
floodfill(highlightx, highlighty, LIGHTGREEN);
setcolor(BLACK);
setfillstyle(SOLID_FILL, BLACK);
rectangle(0, 0, 640, 40);
floodfill(2, 2, BLACK);
setcolor(BLACK);
outtextxy(10, 10, "White player, please highlight the square you would like to place");
outtextxy(10, 30, "your chip in. Enter 'S' when the proper square is selected. Enter 'X' to Exit.");
setcolor(LIGHTGREEN);
outtextxy(10, 10, "Black player, please highlight the square you would like to place");
outtextxy(10, 30, "your chip in. Press Enter when the proper square is selected. Enter 'X' to Exit.");
do
{
setcolor(LIGHTGREEN);
gotoxy(1, 10);
key = getch();
//direction commands
if ((key == 72)&&(highlighty - sqsize > centery - sqsize * 3))
{
setfillstyle(SOLID_FILL, GREEN);
floodfill(highlightx, highlighty, LIGHTGREEN);
highlighty = highlighty - sqsize;
setfillstyle(SOLID_FILL, BLUE);
floodfill(highlightx, highlighty, LIGHTGREEN);
}
if ((key == 80)&&(highlighty + sqsize < centery + sqsize * 3))
{
setfillstyle(SOLID_FILL, GREEN);
floodfill(highlightx, highlighty, LIGHTGREEN);
highlighty = highlighty + sqsize;
setfillstyle(SOLID_FILL, BLUE);
floodfill(highlightx, highlighty, LIGHTGREEN);
}
if ((key == 77)&&(highlightx + sqsize < centerx + 3 * sqsize))
{
setfillstyle(SOLID_FILL, GREEN);
floodfill(highlightx, highlighty, LIGHTGREEN);
highlightx = highlightx + sqsize;
setfillstyle(SOLID_FILL, BLUE);
floodfill(highlightx, highlighty, LIGHTGREEN);
}
if ((key == 75)&&(highlightx - sqsize > centerx - 3*sqsize))
{
setfillstyle(SOLID_FILL, GREEN);
floodfill(highlightx, highlighty, LIGHTGREEN);
highlightx = highlightx - sqsize;
setfillstyle(SOLID_FILL, BLUE);
floodfill(highlightx, highlighty, LIGHTGREEN);
}
}while ((key != 13)&&(key != 120));
if (key == 120)
{
tcount = 6;
count = 3;
}
else
{
selectx = highlightx + 2 - sqsize/2;
selecty = highlighty - 2 + sqsize/2;
checkx = selectx;
checky = selecty;
wrongmove = 0;
valid = FALSE;
arrayidentity();
if (array[a][b] == 'g')
{
if (checkx - 2*sqsize > centerx - 3 *sqsize)
{
//checking left for validity
do
{
checkx = checkx - sqsize;
arrayidentity();
if (array[a][b] == 'b')
{
checkx = checkx + sqsize;
arrayidentity();
if (array[a][b] == 'w')
{
valid = TRUE;
b1 = b;
farx = checkx;
wrongmove = wrongmove + 1;
}
}
} while ((checkx > centerx - 3*sqsize)&&(array[a][b] == 'w')&&(valid == FALSE));
checkx = selectx;
checky = selecty;
if (valid == TRUE)
{
setcolor(LIGHTGREEN);
circle(selectx, selecty, radius);
setfillstyle(SOLID_FILL, GREEN);
floodfill(selectx + sqsize/2 - 2, selecty, LIGHTGREEN);
setfillstyle(SOLID_FILL, BLACK);
floodfill(selectx, selecty, LIGHTGREEN);
arrayidentity();
array[a][b] = 'b';
//filling in other circles
for (int f = b1; f <= b; ++f)
array[a][f] = 'b';
//filling in the board
for (checkx = farx; checkx <= selectx; checkx = checkx + sqsize)
floodfill(checkx, checky, LIGHTGREEN);
}
}
checkx = selectx;
checky = selecty;
valid = FALSE;
if (checkx + 2*sqsize < centerx + 3*sqsize)
{
//while loop to check right for validity
do
{
checkx = checkx + sqsize;
arrayidentity();
if (array[a][b] == 'b')
{
checkx = checkx - sqsize;
arrayidentity();
if (array[a][b] == 'w')
{
valid = TRUE;
b1 = b;
farx = checkx;
wrongmove = wrongmove + 1;
}
}
}while ((checkx < centerx + 3*sqsize)&&(array[a][b] == 'w')&&(valid == FALSE));
checkx = selectx;
checky = selecty;
if (valid == TRUE)
{
setcolor(LIGHTGREEN);
circle(selectx, selecty, radius);
setfillstyle(SOLID_FILL, GREEN);
floodfill(selectx + sqsize/2 - 2, selecty, LIGHTGREEN);
setfillstyle(SOLID_FILL, BLACK);
floodfill(selectx, selecty, LIGHTGREEN);
arrayidentity();
array[a][b] = 'b';
//filling in the array
for (int f = b1; f >= b; --f)
{
setfillstyle(SOLID_FILL, BLACK);
floodfill(checkx, checky, LIGHTGREEN);
array[a][f] = 'b';
}
//filling in the board
for (checkx = farx; checkx >= selectx; checkx = checkx - sqsize)
floodfill(checkx, checky, LIGHTGREEN);
}
}
checky = selecty;
checkx = selectx;
valid = FALSE;
if (checky + 2*sqsize < centery + 3*sqsize)
{
//while loop to check down for validity
do
{
checky = checky + sqsize;
arrayidentity();
if (array[a][b] == 'b')
{
checky = checky - sqsize;
arrayidentity();
if (array[a][b] == 'w')
{
valid = TRUE;
a1 = a;
fary = checky;
wrongmove = wrongmove + 1;
}
}
}while ((checky < centery + 3 * sqsize)&&(array[a][b] == 'w')&&(valid == FALSE));
checkx = selectx;
checky = selecty;
if (valid == TRUE)
{
setcolor(LIGHTGREEN);
setfillstyle(SOLID_FILL, GREEN);
floodfill(selectx + sqsize/2 - 2, selecty, LIGHTGREEN);
circle(selectx, selecty, radius);
setfillstyle(SOLID_FILL, BLACK);
floodfill(selectx, selecty, LIGHTGREEN);
arrayidentity();
array[a][b] = 'b';
//filling in array
for (int f = a1; f >= a; --f)
array[f][b] = 'b';
//filling in circles
for (checky = fary; checky >= selecty; checky = checky - sqsize)
floodfill(checkx, checky, LIGHTGREEN);
}
}
checky = selecty;
checkx = selectx;
valid = FALSE;
if (checky - 2*sqsize > centery - 3*sqsize)
{
//while loop to check up
do
{
checky = checky - sqsize;
arrayidentity();
if (array[a][b] == 'b')
{
checky = checky + sqsize;
arrayidentity();
if (array[a][b] == 'w')
{
wrongmove = wrongmove +1;
valid = TRUE;
a1 = a;
fary = checky;
}
}
}while ((checky > centery - 3*sqsize)&&(array[a][b] == 'w')&&(valid == FALSE));
checkx = selectx;
checky = selecty;
if (valid == TRUE)
{
setcolor(LIGHTGREEN);
setfillstyle(SOLID_FILL, GREEN);
floodfill(selectx + sqsize/2 - 2, selecty, LIGHTGREEN);
circle(selectx, selecty, radius);
setfillstyle(SOLID_FILL, BLACK);
floodfill(selectx, selecty, LIGHTGREEN);
arrayidentity();
array[a][b] = 'b';
//filling in array
for (int f = a1; f <= a; ++f)
array[f][b] = 'b';
//filling in other circles
for (checky = fary; checky <= selecty; checky = checky + sqsize)
floodfill(checkx, checky, LIGHTGREEN);
}
}
checkx = selectx;
checky = selecty;
valid = FALSE;
if (checky - 2*sqsize > centery - 3*sqsize)
{
//while loop to check up diagonally left
do
{
checky = checky - sqsize;
checkx = checkx - sqsize;
arrayidentity();
if (array[a][b] == 'b')
{
checky = checky + sqsize;
checkx = checkx + sqsize;
arrayidentity();
if (array[a][b] == 'w')
{
valid = TRUE;
wrongmove = wrongmove + 1;
a1 = a;
b1 = b;
farx = checkx;
fary = checky;
}
}
} while ((checkx > centerx - 3*sqsize)&&(array[a][b] == 'w')&&(valid == FALSE));
checkx = selectx;
checky = selecty;
if (valid == TRUE)
{
setcolor(LIGHTGREEN);
circle(selectx, selecty, radius);
setfillstyle(SOLID_FILL, GREEN);
floodfill(selectx + sqsize/2 - 2, selecty, LIGHTGREEN);
setfillstyle(SOLID_FILL, BLACK);
floodfill(selectx, selecty, LIGHTGREEN);
arrayidentity();
array[a][b] = 'b';
//filling in other circles
for (int f = b; f >= b1; --f)
{
array[a][f] = 'b';
a = a-1;
}
for (checkx = selectx; checkx >= farx; checkx = checkx - sqsize)
{
floodfill(checkx, checky, LIGHTGREEN);
checky = checky - sqsize;
}
}
checkx = selectx;
checky = selecty;
valid = FALSE;
}
if ((checkx + 2*sqsize < centerx + 3*sqsize)&&
(checky - 2*sqsize > centery - 3*sqsize))
{
//WHILE LOOP TO CHECK DIAGONALLY UP RIGHT
do
{
checkx = checkx + sqsize;
checky = checky - sqsize;
arrayidentity();
if (array[a][b] == 'b')
{
checkx = checkx - sqsize;
checky = checky + sqsize;
arrayidentity();
if (array[a][b] == 'w')
{
valid = TRUE;
a1 = a;
b1 = b;
farx = checkx;
fary = checky;
wrongmove = wrongmove + 1;
}
}
}while ((checkx < centerx + 3*sqsize)&&(array[a][b] == 'w')&&(valid == FALSE));
checkx = selectx;
checky = selecty;
if (valid == TRUE)
{
setcolor(LIGHTGREEN);
circle(selectx, selecty, radius);
setfillstyle(SOLID_FILL, GREEN);
floodfill(selectx + sqsize/2 - 2, selecty, LIGHTGREEN);
setfillstyle(SOLID_FILL, BLACK);
floodfill(selectx, selecty, LIGHTGREEN);
arrayidentity();
array[a][b] = 'b';
//filling in other circles
for (int f = b; f <= b1; ++f)
{
array[a][f] = 'b';
a = a-1;
}
for (checkx = selectx; checkx <= farx; checkx = checkx + sqsize)
{
floodfill(checkx, checky, LIGHTGREEN);
checky = checky - sqsize;
}
}
}
checkx = selectx;
checky = selecty;
valid = FALSE;
if ((checkx - 2*sqsize > centerx - 3*sqsize)&&
(checky + 2*sqsize < centery + 3*sqsize))
{
//WHILE LOOP TO CHECK DOWN DIAGONALLY LEFT
do
{
checkx = checkx - sqsize;
checky = checky + sqsize;
arrayidentity();
if (array[a][b] == 'b')
{
checkx = checkx + sqsize;
checky = checky - sqsize;
arrayidentity();
if (array[a][b] == 'w')
{
valid = TRUE;
a1 =a;
b1 = b;
farx = checkx;
fary = checky;
wrongmove = wrongmove + 1;
}
}
} while ((checky < centery + 3*sqsize)&&(array[a][b] == 'w')&&(valid == FALSE));
checkx = selectx;
checky = selecty;
if (valid == TRUE)
{
setcolor(LIGHTGREEN);
circle(selectx, selecty, radius);
setfillstyle(SOLID_FILL, GREEN);
floodfill(selectx + sqsize/2 - 2, selecty, LIGHTGREEN);
setfillstyle(SOLID_FILL, BLACK);
floodfill(selectx, selecty, LIGHTGREEN);
arrayidentity();
array[a][b] = 'b';
//filling in array
for (int f = a; f <= a1; ++f)
{
array[f][b] = 'b';
b = b-1;
}
//filling in circles
for (checkx = selectx; checkx >= farx; checkx = checkx - sqsize)
{
floodfill(checkx, checky, LIGHTGREEN);
checky = checky + sqsize;
}
}
}
checkx = selectx;
checky = selecty;
valid = FALSE;
if ((checkx + 2*sqsize < centerx + 3*sqsize)&&
(checky + 2*sqsize < centery + 3*sqsize))
{
//while loop to check down diagonally right
do
{
checkx = checkx + sqsize;
checky = checky + sqsize;
arrayidentity();
if (array[a][b] == 'b')
{
checkx = checkx - sqsize;
checky = checky - sqsize;
arrayidentity();
if (array[a][b] == 'w')
{
a1 = a;
b1 = b;
farx = checkx;
fary = checky;
valid = TRUE;
wrongmove = wrongmove + 1;
}
}
}while ((checky < centery + 3*sqsize)&&(array[a][b] == 'w')&&(valid == FALSE));
checkx = selectx;
checky = selecty;
if (valid == TRUE)
{
setcolor(LIGHTGREEN);
circle(selectx, selecty, radius);
setfillstyle(SOLID_FILL, GREEN);
floodfill(selectx + sqsize/2 - 2, selecty, LIGHTGREEN);
setfillstyle(SOLID_FILL, BLACK);
floodfill(selectx, selecty, LIGHTGREEN);
arrayidentity();
array[a][b] = 'b';
//filling in array
for (int f = a; f <= a1; ++f)
{
array[f][b] = 'b';
b = b+1;
}
//fillingi n circles
for (checkx = selectx; checkx <= farx; checkx = checkx + sqsize)
{
floodfill(checkx, checky, LIGHTGREEN);
checky = checky + sqsize;
}
}
}
}
checkx = selectx;
checky = selecty;
blackcount = 0;
whitecount = 0;
if (wrongmove == 0)
{
//fill in the selected square green
setfillstyle(SOLID_FILL, GREEN);
floodfill(selectx+sqsize/2 - 2, selecty+ sqsize/2 - 2, LIGHTGREEN);
}
for(a = 1; a <= 6; ++a)
{
for (b = 1; b <= 6; ++b)
{
if (array[a][b] == 'b')
blackcount = blackcount + 1;
if (array[a][b] == 'w')
whitecount = whitecount +1;
}
}
setcolor(LIGHTGREEN);
setfillstyle(SOLID_FILL, BLUE);
rectangle(580, 90, 620, 150);
floodfill(590, 110, LIGHTGREEN);
setfillstyle(SOLID_FILL, BLACK);
floodfill(590, 110, BLACK);
setcolor(LIGHTGREEN);
outtextxy(480, 100, "Black chips: ");
gotoxy(75, 7);
cout << blackcount;
outtextxy(480, 120, "White chips: ");
gotoxy(75, 8);
cout << whitecount;
}
setcolor(BLUE);
rectangle(0, 130, 50, 250);
setfillstyle(SOLID_FILL, LIGHTGREEN);
floodfill(2, 150, BLUE);
setfillstyle(SOLID_FILL, BLACK);
floodfill(2, 150, BLUE);
setcolor(BLACK);
rectangle(0, 130, 50, 250);
setcolor(LIGHTGREEN);
}
Othello::arrayidentity()
{
if (checkx == centerx - sqsize/2)
b = 3;
if (checkx == centerx - sqsize/2 - sqsize)
b = 2;
if (checkx == centerx - sqsize/2 - 2*sqsize)
b = 1;
if (checkx == centerx + sqsize/2)
b = 4;
if (checkx == centerx + sqsize/2 + sqsize)
b = 5;
if (checkx == centerx + sqsize/2 + 2*sqsize)
b = 6;
if (checky == centery - sqsize/2)
a = 3;
if (checky == centery - sqsize/2 - sqsize)
a = 2;
if (checky == centery - sqsize/2 - 2*sqsize)
a = 1;
if (checky == centery + sqsize/2)
a = 4;
if (checky == centery + sqsize/2 + sqsize)
a = 5;
if (checky == centery + sqsize/ 2 + 2*sqsize)
a = 6;
}
Othello::whitemove()
{
//beginning highlighted square
setfillstyle(SOLID_FILL, BLUE);
highlightx = centerx + sqsize - 2;
highlighty = centery - sqsize +2;
floodfill(highlightx, highlighty, LIGHTGREEN);
setcolor(BLACK);
setfillstyle(SOLID_FILL, BLACK);
rectangle(0, 0, 640, 40);
floodfill(2, 2, BLACK);
setcolor(BLACK);
outtextxy(10, 10, "Black player, please highlight the square you would like to place");
outtextxy(10, 30, "your chip in. Enter 'S' when the proper square is selected. Enter 'X' to Exit.");
setcolor(LIGHTGREEN);
outtextxy(10, 10, "White player, please highlight the square you would like to place");
outtextxy(10, 30, "your chip in. Press Enter when the proper square is selected. Enter 'X' to Exit.");
do
{
setcolor(LIGHTGREEN);
gotoxy(1, 10);
key = getch();
//direction commands
if ((key == 72)&&(highlighty - sqsize > centery - sqsize * 3))
{
setfillstyle(SOLID_FILL, GREEN);
floodfill(highlightx, highlighty, LIGHTGREEN);
highlighty = highlighty - sqsize;
setfillstyle(SOLID_FILL, BLUE);
floodfill(highlightx, highlighty, LIGHTGREEN);
}
if ((key == 80)&&(highlighty + sqsize < centery + sqsize * 3))
{
setfillstyle(SOLID_FILL, GREEN);
floodfill(highlightx, highlighty, LIGHTGREEN);
highlighty = highlighty + sqsize;
setfillstyle(SOLID_FILL, BLUE);
floodfill(highlightx, highlighty, LIGHTGREEN);
}
if ((key == 77)&&(highlightx + sqsize < centerx + 3 * sqsize))
{
setfillstyle(SOLID_FILL, GREEN);
floodfill(highlightx, highlighty, LIGHTGREEN);
highlightx = highlightx + sqsize;
setfillstyle(SOLID_FILL, BLUE);
floodfill(highlightx, highlighty, LIGHTGREEN);
}
if ((key == 75)&&(highlightx - sqsize > centerx - 3*sqsize))
{
setfillstyle(SOLID_FILL, GREEN);
floodfill(highlightx, highlighty, LIGHTGREEN);
highlightx = highlightx - sqsize;
setfillstyle(SOLID_FILL, BLUE);
floodfill(highlightx, highlighty, LIGHTGREEN);
}
}while ((key != 13)&&(key != 120));
if (key == 120)
{
tcount = 6;
count = 3;
}
else
{
selectx = highlightx + 2 - sqsize/2;
selecty = highlighty - 2 + sqsize/2;
checkx = selectx;
checky = selecty;
wrongmove = 0;
valid = FALSE;
arrayidentity();
if (array[a][b] == 'g')
{
if (checkx - 2*sqsize > centerx - 3 *sqsize)
{
//checking left for validity
do
{
checkx = checkx - sqsize;
arrayidentity();
if (array[a][b] == 'w')
{
checkx = checkx + sqsize;
arrayidentity();
if (array[a][b] == 'b')
{
valid = TRUE;
b1 = b;
farx = checkx;
wrongmove = wrongmove + 1;
}
}
} while ((checkx > centerx - 3*sqsize)&&(array[a][b] == 'b')&&(valid == FALSE));
checkx = selectx;
checky = selecty;
if (valid == TRUE)
{
setcolor(LIGHTGREEN);
circle(selectx, selecty, radius);
setfillstyle(SOLID_FILL, GREEN);
floodfill(selectx + sqsize/2 - 2, selecty, LIGHTGREEN);
setfillstyle(SOLID_FILL, WHITE);
floodfill(selectx, selecty, LIGHTGREEN);
arrayidentity();
array[a][b] = 'w';
//filling in other circles
for (int f = b1; f <= b; ++f)
array[a][f] = 'w';
//filling in the board
for (checkx = farx; checkx <= selectx; checkx = checkx + sqsize)
floodfill(checkx, checky, LIGHTGREEN);
}
}
checkx = selectx;
checky = selecty;
valid = FALSE;
if (checkx + 2*sqsize < centerx + 3*sqsize)
{
//while loop to check right for validity
do
{
checkx = checkx + sqsize;
arrayidentity();
if (array[a][b] == 'w')
{
checkx = checkx - sqsize;
arrayidentity();
if (array[a][b] == 'b')
{
valid = TRUE;
b1 = b;
farx = checkx;
wrongmove = wrongmove + 1;
}
}
}while ((checkx < centerx + 3*sqsize)&&(array[a][b] == 'b')&&(valid == FALSE));
checkx = selectx;
checky = selecty;
if (valid == TRUE)
{
setcolor(LIGHTGREEN);
circle(selectx, selecty, radius);
setfillstyle(SOLID_FILL, GREEN);
floodfill(selectx + sqsize/2 - 2, selecty, LIGHTGREEN);
setfillstyle(SOLID_FILL, WHITE);
floodfill(selectx, selecty, LIGHTGREEN);
arrayidentity();
array[a][b] = 'w';
//filling in the array
for (int f = b1; f >= b; --f)
{
setfillstyle(SOLID_FILL, WHITE);
floodfill(checkx, checky, LIGHTGREEN);
array[a][f] = 'w';
}
//filling in the board
for (checkx = farx; checkx >= selectx; checkx = checkx - sqsize)
floodfill(checkx, checky, LIGHTGREEN);
// for (a = 1; a<= 6; ++a)
// {
// for (b = 1; b <= 6; ++b)
// cout << array[a][b] << " ";
// cout << endl;
// }
}
}
checky = selecty;
checkx = selectx;
valid = FALSE;
if (checky + 2*sqsize < centery + 3*sqsize)
{
//while loop to check down for validity
do
{
checky = checky + sqsize;
arrayidentity();
if (array[a][b] == 'w')
{
checky = checky - sqsize;
arrayidentity();
if (array[a][b] == 'b')
{
valid = TRUE;
a1 = a;
fary = checky;
wrongmove = wrongmove + 1;
}
}
}while ((checky < centery + 3 * sqsize)&&(array[a][b] == 'b')&&(valid == FALSE));
checkx = selectx;
checky = selecty;
if (valid == TRUE)
{
setcolor(LIGHTGREEN);
setfillstyle(SOLID_FILL, GREEN);
floodfill(selectx + sqsize/2 - 2, selecty, LIGHTGREEN);
circle(selectx, selecty, radius);
setfillstyle(SOLID_FILL, WHITE);
floodfill(selectx, selecty, LIGHTGREEN);
arrayidentity();
array[a][b] = 'w';
//filling in array
for (int f = a1; f >= a; --f)
array[f][b] = 'w';
//filling in circles
for (checky = fary; checky >= selecty; checky = checky - sqsize)
floodfill(checkx, checky, LIGHTGREEN);
}
}
checky = selecty;
checkx = selectx;
valid = FALSE;
if (checky - 2*sqsize > centery - 3*sqsize)
{
//while loop to check up
do
{
checky = checky - sqsize;
arrayidentity();
if (array[a][b] == 'w')
{
checky = checky + sqsize;
arrayidentity();
if (array[a][b] == 'b')
{
wrongmove = wrongmove +1;
valid = TRUE;
a1 = a;
fary = checky;
}
}
}while ((checky > centery - 3*sqsize)&&(array[a][b] == 'b')&&(valid == FALSE));
checkx = selectx;
checky = selecty;
if (valid == TRUE)
{
setcolor(LIGHTGREEN);
setfillstyle(SOLID_FILL, GREEN);
floodfill(selectx + sqsize/2 - 2, selecty, LIGHTGREEN);
circle(selectx, selecty, radius);
setfillstyle(SOLID_FILL, WHITE);
floodfill(selectx, selecty, LIGHTGREEN);
arrayidentity();
array[a][b] = 'w';
//filling in array
for (int f = a1; f <= a; ++f)
array[f][b] = 'w';
//filling in other circles
for (checky = fary; checky <= selecty; checky = checky + sqsize)
floodfill(checkx, checky, LIGHTGREEN);
}
}
checkx = selectx;
checky = selecty;
valid = FALSE;
if ((checky - 2*sqsize > centery - 3*sqsize)&&
(checkx - 2*sqsize > centerx - 3*sqsize))
{
//while loop to check up diagonally left
do
{
checky = checky - sqsize;
checkx = checkx - sqsize;
arrayidentity();
if (array[a][b] == 'w')
{
checky = checky + sqsize;
checkx = checkx + sqsize;
arrayidentity();
if (array[a][b] == 'b')
{
valid = TRUE;
wrongmove = wrongmove + 1;
a1 = a;
b1 = b;
farx = checkx;
fary = checky;
}
}
} while ((checkx > centerx - 3*sqsize)&&(array[a][b] == 'b')&&(valid == FALSE));
checkx = selectx;
checky = selecty;
if (valid == TRUE)
{
setcolor(LIGHTGREEN);
circle(selectx, selecty, radius);
setfillstyle(SOLID_FILL, GREEN);
floodfill(selectx + sqsize/2 - 2, selecty, LIGHTGREEN);
setfillstyle(SOLID_FILL, WHITE);
floodfill(selectx, selecty, LIGHTGREEN);
arrayidentity();
array[a][b] = 'w';
//filling in other circles
for (int f = b; f >= b1; --f)
{
array[a][f] = 'w';
a = a-1;
}
for (checkx = selectx; checkx >= farx; checkx = checkx - sqsize)
{
floodfill(checkx, checky, LIGHTGREEN);
checky = checky - sqsize;
}
}
}
checkx = selectx;
checky = selecty;
valid = FALSE;
if ((checkx + 2*sqsize < centerx + 3*sqsize)&&
(checky - 2*sqsize > centery - 3*sqsize))
{
//WHILE LOOP TO CHECK DIAGONALLY UP RIGHT
do
{
checkx = checkx + sqsize;
checky = checky - sqsize;
arrayidentity();
if (array[a][b] == 'w')
{
checkx = checkx - sqsize;
checky = checky + sqsize;
arrayidentity();
if (array[a][b] == 'b')
{
valid = TRUE;
a1 = a;
b1 = b;
farx = checkx;
fary = checky;
wrongmove = wrongmove + 1;
}
}
}while ((checkx < centerx + 3*sqsize)&&(array[a][b] == 'b')&&(valid == FALSE));
checkx = selectx;
checky = selecty;
if (valid == TRUE)
{
setcolor(LIGHTGREEN);
circle(selectx, selecty, radius);
setfillstyle(SOLID_FILL, GREEN);
floodfill(selectx + sqsize/2 - 2, selecty, LIGHTGREEN);
setfillstyle(SOLID_FILL, WHITE);
floodfill(selectx, selecty, LIGHTGREEN);
arrayidentity();
array[a][b] = 'w';
//filling in other circles
for (int f = b; f <= b1; ++f)
{
array[a][f] = 'w';
a = a-1;
}
for (checkx = selectx; checkx <= farx; checkx = checkx + sqsize)
{
floodfill(checkx, checky, LIGHTGREEN);
checky = checky - sqsize;
}
}
// for (checkx = farx; checkx <= farx; checkx = checkx + sqsize)
// {
// checky = checky - sqsize;
// floodfill(checkx, checky, LIGHTGREEN);
// }
}
checkx = selectx;
checky = selecty;
valid = FALSE;
if ((checkx - 2*sqsize > centerx - 3*sqsize)&&
(checky + 2*sqsize < centery + 3*sqsize))
{
//WHILE LOOP TO CHECK DOWN DIAGONALLY LEFT
do
{
checkx = checkx - sqsize;
checky = checky + sqsize;
arrayidentity();
if (array[a][b] == 'w')
{
checkx = checkx + sqsize;
checky = checky - sqsize;
arrayidentity();
if (array[a][b] == 'b')
{
valid = TRUE;
a1 =a;
b1 = b;
farx = checkx;
fary = checky;
wrongmove = wrongmove + 1;
}
}
} while ((checky < centery + 3*sqsize)&&(array[a][b] == 'b')&&(valid == FALSE));
checkx = selectx;
checky = selecty;
if (valid == TRUE)
{
setcolor(LIGHTGREEN);
circle(selectx, selecty, radius);
setfillstyle(SOLID_FILL, GREEN);
floodfill(selectx + sqsize/2 - 2, selecty, LIGHTGREEN);
setfillstyle(SOLID_FILL, WHITE);
floodfill(selectx, selecty, LIGHTGREEN);
arrayidentity();
array[a][b] = 'w';
//filling in array
for (int f = a; f <= a1; ++f)
{
array[f][b] = 'w';
b = b-1;
}
//filling in circles
for (checkx = selectx; checkx >= farx; checkx = checkx - sqsize)
{
floodfill(checkx, checky, LIGHTGREEN);
checky = checky + sqsize;
}
}
}
checkx = selectx;
checky = selecty;
valid = FALSE;
if ((checkx + 2*sqsize < centerx + 3*sqsize)&&
(checky + 2*sqsize < centery + 3*sqsize))
{
//while loop to check down diagonally right
do
{
checkx = checkx + sqsize;
checky = checky + sqsize;
arrayidentity();
if (array[a][b] == 'w')
{
checkx = checkx - sqsize;
checky = checky - sqsize;
arrayidentity();
if (array[a][b] == 'b')
{
a1 = a;
b1 = b;
farx = checkx;
fary = checky;
valid = TRUE;
wrongmove = wrongmove + 1;
}
}
}while ((checky < centery + 3*sqsize)&&(array[a][b] == 'b')&&(valid == FALSE));
checkx = selectx;
checky = selecty;
if (valid == TRUE)
{
setcolor(LIGHTGREEN);
circle(selectx, selecty, radius);
setfillstyle(SOLID_FILL, GREEN);
floodfill(selectx + sqsize/2 - 2, selecty, LIGHTGREEN);
setfillstyle(SOLID_FILL, WHITE);
floodfill(selectx, selecty, LIGHTGREEN);
arrayidentity();
array[a][b] = 'w';
//filling in array
for (int f = a; f <= a1; ++f)
{
array[f][b] = 'w';
b = b+1;
}
//fillingi n circles
for (checkx = selectx; checkx <= farx; checkx = checkx + sqsize)
{
floodfill(checkx, checky, LIGHTGREEN);
checky = checky + sqsize;
}
}
} }
checkx = selectx;
checky = selecty;
blackcount = 0;
whitecount = 0;
if (wrongmove == 0)
{
//fill in the selected square green
setfillstyle(SOLID_FILL, GREEN);
floodfill(selectx + sqsize/2 - 2, selecty+ sqsize/2 -2, LIGHTGREEN);
}
for(a = 1; a <= 6; ++a)
{
for (b = 1; b <= 6; ++b)
{
if (array[a][b] == 'b')
blackcount = blackcount + 1;
if (array[a][b] == 'w')
whitecount = whitecount +1;
}
}
setcolor(LIGHTGREEN);
setfillstyle(SOLID_FILL, BLUE);
rectangle(580, 90, 620, 150);
floodfill(590, 110, LIGHTGREEN);
// getch();
setfillstyle(SOLID_FILL, BLACK);
floodfill(590, 110, BLACK);
setcolor(LIGHTGREEN);
outtextxy(480, 100, "Black chips: ");
gotoxy(75, 7);
cout << blackcount;
outtextxy(480, 120, "White chips: ");
gotoxy(75, 8);
cout << whitecount;
}
setcolor(BLUE);
rectangle(0, 130, 50, 250);
setfillstyle(SOLID_FILL, LIGHTGREEN);
floodfill(2, 150, BLUE);
setfillstyle(SOLID_FILL, BLACK);
floodfill(2, 150, BLUE);
setcolor(BLACK);
rectangle(0, 130, 50, 250);
setcolor(LIGHTGREEN);
}
Othello::play()
{
done = 'Y';
wrongmove = 0;
direction = 'U';
do
{
wrongmove = 0;
count = 1;
tcount = 1;
while ((wrongmove == 0)&&(count <= 3))
{
blackmove();
count = count + 1;
tcount = tcount + 1;
}
count = 1;
wrongmove = 0;
if ((blackcount + whitecount < 36)&&(direction != 'X'))
{
while ((wrongmove == 0)&&(count <=3))
{
whitemove();
count = count +1;
tcount = tcount +1;
}
if ((tcount >= 6)&&(direction != 'X'))
{
outtextxy(10, 200, "Are there any");
outtextxy(10, 210, "valid moves left?");
gotoxy(2, 15);
cin >> done;
if ((done == 'Y')||(done == 'y'))
{
setcolor(BLACK);
outtextxy(10, 200, "Are there any");
outtextxy(10, 210, "valid moves left?");
gotoxy(2, 15);
cout << done;
setcolor(LIGHTGREEN);
}
done = toupper(done);
}
}
}while ((blackcount + whitecount < 36)&&(done != 'N')&&(blackcount != 0)&&(whitecount !=0)&&(direction != 'X'));
if (direction != 'X')
{
delay(750);
winner();
}
}
Othello::winner()
{
clrscr();
cleardevice();
setbkcolor(BLACK);
gotoxy(30, 10);
cout << "Way to go ";
if (blackcount > whitecount)
cout << play1 << "!" << endl;
if (whitecount > blackcount)
cout << play2 << "!" << endl;
setcolor(WHITE);
settextstyle(TRIPLEX_FONT, HORIZ_DIR, 3);
outtextxy(120, 155, "You're the Othello Champ!");
//DRAW CIRCLES
setcolor(WHITE);
circle(150, 300, 50);
circle(300, 300, 50);
circle(450, 300, 50);
if(blackcount > whitecount)
{
setfillstyle(SOLID_FILL, WHITE);
floodfill(150, 300, WHITE);
floodfill(300, 300, WHITE);
floodfill(450, 300, WHITE);
setfillstyle(SOLID_FILL, BLACK);
delay(750);
floodfill(150, 300, BLACK);
setcolor(WHITE);
circle(150, 300, 50);
delay(750);
floodfill(300, 300, BLACK);
circle(300, 300, 50);
delay(750);
floodfill(450, 300, BLACK);
circle(450, 300, 50);
}
if (whitecount > blackcount)
{
setfillstyle(SOLID_FILL, BLACK);
floodfill(150, 300, WHITE);
floodfill(300, 300, WHITE);
floodfill(450, 300, WHITE);
delay(750);
setfillstyle(SOLID_FILL, WHITE);
floodfill(150, 300, WHITE);
delay(750);
floodfill(300, 300, WHITE);
delay(750);
floodfill(450, 300, WHITE);
}
}
It also has two included files, apstring.inc and bool.h --I found the bool.h and an apstring.h on the disk as well, and those look like this:
#ifndef _APSTRING_H
#define _APSTRING_H
#include <iostream.h>
// uncomment line below if bool not built-in type
#include "bool.h"
// *******************************************************************
// Last Revised: 8/14/98
// corrected comments
//
// 6/29/98 - commented out the #include "bool.h", dhj
//
// APCS string class
//
// string class consistent with a subset of the standard C++ string class
// as defined in the draft ANSI standard
// *******************************************************************
extern const int npos; // used to indicate not a position in the string
class apstring
{
public:
// constructors/destructor
apstring( ); // construct empty string ""
apstring( const char * s ); // construct from string literal
apstring( const apstring & str ); // copy constructor
~apstring( ); // destructor
// assignment
const apstring & operator = ( const apstring & str ); // assign str
const apstring & operator = ( const char * s ); // assign s
const apstring & operator = ( char ch ); // assign ch
// accessors
int length( ) const; // number of chars
int find( const apstring & str ) const; // index of first occurrence of str
int find( char ch ) const; // index of first occurrence of ch
apstring substr( int pos, int len ) const; // substring of len chars
// starting at pos
const char * c_str( ) const; // explicit conversion to char *
// indexing
char operator[ ]( int k ) const; // range-checked indexing
char & operator[ ]( int k ); // range-checked indexing
// modifiers
const apstring & operator += ( const apstring & str );// append str
const apstring & operator += ( char ch ); // append char
private:
int myLength; // length of string (# of characters)
int myCapacity; // capacity of string
char * myCstring; // storage for characters
};
// The following free (non-member) functions operate on strings
//
// I/O functions
ostream & operator << ( ostream & os, const apstring & str );
istream & operator >> ( istream & is, apstring & str );
istream & getline( istream & is, apstring & str );
// comparison operators:
bool operator == ( const apstring & lhs, const apstring & rhs );
bool operator != ( const apstring & lhs, const apstring & rhs );
bool operator < ( const apstring & lhs, const apstring & rhs );
bool operator <= ( const apstring & lhs, const apstring & rhs );
bool operator > ( const apstring & lhs, const apstring & rhs );
bool operator >= ( const apstring & lhs, const apstring & rhs );
// concatenation operator +
apstring operator + ( const apstring & lhs, const apstring & rhs );
apstring operator + ( char ch, const apstring & str );
apstring operator + ( const apstring & str, char ch );
// *******************************************************************
// Specifications for string functions
//
// Any violation of a function's precondition will result in an error
// message followed by a call to assert.
//
// The apstring class assumes that '\0' is not a valid
// character in an apstring. Any attempts to place '\0'
// in an apstring will result in undefined behavior. Generally
// this means that characters that follow the '\0' will not
// be considered part of the apstring for purposes of
// comparison, output, and subsequent copying.
//
// constructors / destructor
//
// string( )
// postcondition: string is empty
//
// string( const char * s )
// description: constructs a string object from a literal string
// such as "abcd"
// precondition: s is '\0'-terminated string as used in C
// postcondition: copy of s has been constructed
//
// string( const string & str )
// description: copy constructor
// postcondition: copy of str has been constructed
//
// ~string( );
// description: destructor
// postcondition: string is destroyed
//
// assignment
//
// string & operator = ( const string & rhs )
// postcondition: normal assignment via copying has been performed
//
// string & operator = ( const char * s )
// description: assignment from literal string such as "abcd"
// precondition: s is '\0'-terminated string as used in C
// postcondition: assignment via copying of s has been performed
//
// string & operator = ( char ch )
// description: assignment from character as though single char string
// postcondition: assignment of one-character string has been performed
//
// accessors
//
// int length( ) const;
// postcondition: returns # of chars in string
//
// int find( const string & str) const;
// description: find the first occurrence of the string str within this
// string and return the index of the first character. If
// str does not occur in this string, then return npos.
// precondition: this string represents c0, c1, ..., c(n-1)
// str represents s0, s1, ...,s(m-1)
// postcondition: if s0 == ck0, s1 == ck1, ..., s(m-1) == ck(m-1) and
// there is no j < k0 such that s0 = cj, ...., sm == c(j+m-1),
// then returns k0;
// otherwise returns npos
//
// int find( char ch ) const;
// description: finds the first occurrence of the character ch within this
// string and returns the index. If ch does not occur in this
// string, then returns npos.
// precondition: this string represents c0, c1, ..., c(n-1)
// postcondition: if ch == ck, and there is no j < k such that ch == cj
// then returns k;
// otherwise returns npos
//
// string substr( int pos, int len ) const;
// description: extract and return the substring of length len starting
// at index pos
// precondition: this string represents c0, c1, ..., c(n-1)
// 0 <= pos <= pos + len - 1 < n.
// postcondition: returns the string that represents
// c(pos), c(pos+1), ..., c(pos+len-1)
//
// const char * c_str( ) const;
// description: convert string into a '\0'-terminated string as
// used in C for use with functions
// that have '\0'-terminated string parameters.
// postcondition: returns the equivalent '\0'-terminated string
//
// indexing
//
// char operator [ ]( int k ) const;
// precondition: 0 <= k < length()
// postcondition: returns copy of the kth character
//
// char & operator [ ]( int k )
// precondition: 0 <= k < length()
// postcondition: returns reference to the kth character
// note: if this reference is used to write a '\0'
// subsequent results are undefined
//
// modifiers
//
// const string & operator += ( const string & str )
// postcondition: concatenates a copy of str onto this string
//
// const string & operator += ( char ch )
// postcondition: concatenates a copy of ch onto this string
//
//
// non-member functions
//
// ostream & operator << ( ostream & os, const string & str)
// postcondition: str is written to output stream os
//
// istream & operator >> ( istream & is, string & str )
// precondition: input stream is open for reading
// postcondition: the next string from input stream is has been read
// and stored in str
//
// istream & getline( istream & is, string & str )
// description: reads a line from input stream is into the string str
// precondition: input stream is open for reading
// postcondition: chars from input stream is up to '\n' have been read
// and stored in str; the '\n' has been read but not stored
//
// string operator + ( const string & lhs, const string & rhs )
// postcondition: returns concatenation of lhs with rhs
//
// string operator + ( char ch, const string & str )
// postcondition: returns concatenation of ch with str
//
// string operator + ( const string & str, char ch )
// postcondition: returns concatenation of str with ch
//
//***************************************************************
#endif
And
/ Library file: bool.h
// Defines Boolean constants and a type name for any application.
#ifndef BOOL_H
#undef FALSE
#undef TRUE
const int FALSE = 0;
const int TRUE = 1;
typedef int bool;
#define BOOL_H
#endif
Thank you for any input!