Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "iostream"
- using namespace std;
- int board[3][3];
- int moved=1;
- int moves=0;
- int checkwin()
- {
- int winner=0;
- for (int i=0;i<3;i++)
- {
- if (board[0][i]==board[1][i] and board[1][i]==board[2][i] and board[0][i]!=0)
- winner = board[0][i];
- if (board[i][0]==board[i][1] and board[i][1]==board[i][2] and board[i][0]!=0)
- winner = board[i][0];
- }
- if (board[0][0]==board[1][1] and board[1][1]==board[2][2] and board[0][0]!=0)
- winner = board[0][0];
- if (board[2][0]==board[1][1] and board[1][1]==board[0][2] and board[2][0]!=0)
- winner = board[2][0];
- return winner;
- }
- void checkboard()
- {
- for (int i=0;i<3;i++)
- {
- for (int i1:board[i])
- {
- cout<<i1<<" ";
- }
- cout<<endl;
- }
- cout<<endl;
- }
- int checkpos(int x, int y)
- {
- if (board[y][x]==0)
- {
- moves++;
- board[y][x]=moved;
- moved=1+moved%2;
- int win = checkwin();
- //checkboard();
- if (win!=0)
- return win*10;
- if (win==0 and moves==9)
- return -1;
- return board[y][x];
- }
- else
- return 0;
- }
- int main()
- {
- checkpos(1,2);
- checkboard();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement