1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
#ifndef tictacfuncs_h
#define tictacfuncs_h
#include <iostream>
#include <time.h>
#include <cstdlib>
#include <iomanip>
#include <fstream>
#include "computer_AI.H"
using namespace std;
#define ROWS 3
#define COLS 3
int count = 0;
//int placement = 0;
bool winner = false;
char board[ROWS][COLS] = {'*','*','*',
'*','*','*',
'*','*','*' };
void show_board (char [][COLS]);
//void player_one_pick (int, char[][COLS]);
//void player_two_pick (int, char[][COLS]);
void player_one_turn (char[][COLS]);
void player_two_turn (char[][COLS]);
bool Xwin_condition (bool &, char[][COLS]);
bool Owin_condition (bool &, char[][COLS]);
//void show_help ();
int when_ties (int, bool, int&);
void player_one_turn(char [][COLS])
{
//cout<<"\nComputer player one please input where you want to place an X"<<endl;
comp_x_pick(board);cout<<endl;
//show_board (board);
cout<<endl;
}
void player_two_turn(char [][COLS])
{
//cout<<"\nComputer player two please input where you want to place an O"<<endl;
comp_O_pick(board);cout<<endl;
//show_board(board);
cout<<endl;
}
void show_board(char board[][COLS])
{
cout<<"The Board"<<endl<<
board[0][0]<< board[0][1]<< board[0][2]<<endl<<
board[1][0]<< board[1][1]<< board[1][2]<<endl<<
board[2][0]<< board[2][1]<< board[2][2]<<setw(50);
}
bool Xwin_condition(bool &winner, char board[][COLS])
{ /*all the possible win scenarios for diagonal wins*/
if(((board[0][0] == 'X' && board[1][1] == 'X') && (board[0][0] == 'X' && board[2][2] == 'X')) ||
((board[0][2] == 'X' && board[1][1] == 'X') && (board[0][2] == 'X' && board[2][0] == 'X')) ||
/*all the possible win scenarios for across and down wins*/
((board[0][0] == 'X' && board[1][0] == 'X') && (board[0][0] == 'X' && board[2][0] == 'X')) ||
((board[0][1] == 'X' && board[1][1] == 'X') && (board[0][1] == 'X' && board[2][1] == 'X')) ||
((board[0][2] == 'X' && board[1][2] == 'X') && (board[0][2] == 'X' && board[2][2] == 'X')) ||
((board[2][0] == 'X' && board[2][1] == 'X') && (board[2][0] == 'X' && board[2][2] == 'X')) ||
((board[1][0] == 'X' && board[1][1] == 'X') && (board[1][0] == 'X' && board[1][2] == 'X')) ||
((board[0][0] == 'X' && board[0][1] == 'X') && (board[0][0] == 'X' && board[0][2] == 'X')))
{
winner = true;
}
return winner;
}
bool Owin_condition(bool &winner, char board[][COLS])
{
if(((board[0][0] == 'O' && board[1][1] == 'O') && (board[0][0] == 'O' && board[2][2] == 'O')) ||
((board[0][2] == 'O' && board[1][1] == 'O') && (board[0][2] == 'O' && board[2][0] == 'O')) ||
((board[0][0] == 'O' && board[1][0] == 'O') && (board[0][0] == 'O' && board[2][0] == 'O')) ||
((board[0][1] == 'O' && board[1][1] == 'O') && (board[0][1] == 'O' && board[2][1] == 'O')) ||
((board[0][2] == 'O' && board[1][2] == 'O') && (board[0][2] == 'O' && board[2][2] == 'O')) ||
((board[2][0] == 'O' && board[2][1] == 'O') && (board[2][0] == 'O' && board[2][2] == 'O')) ||
((board[1][0] == 'O' && board[1][1] == 'O') && (board[1][0] == 'O' && board[1][2] == 'O')) ||
((board[0][0] == 'O' && board[0][1] == 'O') && (board[0][0] == 'O' && board[0][2] == 'O')))
{
winner = true;
}
return winner;
}
int when_ties(int count, bool winner, int &ties)
{
if(count >= 9 && (!winner))
{
cout<<"Tie Game! You are both losers!"<<endl;
++ties;
}
return ties;
}
/*
void show_help()
{
cout<<"Each place corresponds to a number, 1-9."<<setw(30)<<endl<<
"1 2 3" <<setw(30)<<endl<<
"4 5 6" <<setw(30)<<endl<<
"7 8 9" <<endl;
*/
}
#endif
| |