Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 11th, 2004, 4:24 PM   #21
Pat
Newbie
 
Pat's Avatar
 
Join Date: Sep 2004
Location: Canada
Posts: 23
Rep Power: 0 Pat is on a distinguished road
Send a message via AIM to Pat Send a message via MSN to Pat
Hehe, wow. He must've been bored that day.
Pat is offline   Reply With Quote
Old Oct 11th, 2004, 4:30 PM   #22
dnathe4th
Programmer
 
Join Date: Oct 2004
Posts: 32
Rep Power: 0 dnathe4th is on a distinguished road
I tried TTT as my first program. I never finished it though, i should get checked for ADD

#include <iostream>
#include <string>
using namespace std;

int winnerz(char current_board[3][3]);
int main()
{
 int x, y;
 char winner, the_move, theres_errors, current_board[3][3];
 for(x=0; x<3; x++)
 {
  for(y=0; y<3; y++)
  {
   current_board[x][y]='-';
  }
 }

system("@echo off");
cout<<"This is standard Tic-Tac-Toe, user vs. computer.";
system("echo.");
cout<<"Use the following board as a key when choosing a position to play:";
system("echo.");
system("echo.");
cout<<"A | B | C";
system("echo.");
cout<<"---------";
system("echo.");
cout<<"D | E | F";
system("echo.");
cout<<"---------";
system("echo.");
cout<<"G | H | I";
system("echo.");
cout<<"Don't forget to use CAPITAL LETTERS";
system("echo.");
system("echo.");
system("echo.");

current_board[1][1] = 'X';

cout<<"Current Board:";
system("echo.");
system("echo.");
cout<<current_board[0][0]<<" | "<<current_board[0][1]<<" | "<<current_board[0][2];
system("echo.");
cout<<"---------";
system("echo.");
cout<<current_board[1][0]<<" | "<<current_board[1][1]<<" | "<<current_board[1][2];
system("echo.");
cout<<"---------";
system("echo.");
cout<<current_board[2][0]<<" | "<<current_board[2][1]<<" | "<<current_board[2][2];
system("echo.");
system("echo.");
cout<<"Please make a move: ";
cin>>the_move;
system("echo.");


while(winner!=1)
{
switch(the_move)
  {
  case 'A': if(current_board[0][0]!='-')
          {
          cout<<"Please move into an unoccupied square. ";
          break;
          }
       else
          {
          current_board[0][0] = 'O';
          break;
          }
   case 'B': if(current_board[0][1]!='-')
          {
          cout<<"Please move into an unoccupied square. ";
          break;
          }
       else
          {
          current_board[0][1] = 'O';
          break;
          }
   case 'C': if(current_board[0][2]!='-')
          {
          cout<<"Please move into an unoccupied square. ";
          break;
          }
       else
          {
          current_board[0][2] = 'O';
          break;
          }
   case 'D': if(current_board[1][0]!='-')
          {
          cout<<"Please move into an unoccupied square. ";
          break;
          }
       else
          {
          current_board[1][0] = 'O';
          break;
          }
   case 'E': if(current_board[1][1]!='-')
          {
          cout<<"Please move into an unoccupied square. ";
          break;
          }
       else
          {
          current_board[1][1] = 'O';
          break;
          }
   case 'F': if(current_board[1][2]!='-')
          {
          cout<<"Please move into an unoccupied square. ";
          break;
          }
       else
          {
          current_board[1][2] = 'O';
          break;
          }
   case 'G': if(current_board[2][0]!='-')
          {
          cout<<"Please move into an unoccupied square";
          break;
          }
       else
          {
          current_board[2][0] = 'O';
          break;
          }
   case 'H': if(current_board[2][1]!='-')
          {
          cout<<"Please move into an unoccupied square";
          break;
          }
       else
          {
          current_board[2][1] = 'O';
          break;
          }
   case 'I': if(current_board[2][2]!='-')
          {
          cout<<"Please move into an unoccupied square";
          break;
          }
       else
          {
          current_board[2][2] = 'O';
          break;
          }
   default: cout<<"Errors have occured. Please restart the program.";
        winner=1;
        theres_errors=1;
  }

if(theres_errors!=1)
{
cout<<"Current Board:";
system("echo.");
system("echo.");
cout<<current_board[0][0]<<" | "<<current_board[0][1]<<" | "<<current_board[0][2];
system("echo.");
cout<<"---------";
system("echo.");
cout<<current_board[1][0]<<" | "<<current_board[1][1]<<" | "<<current_board[1][2];
system("echo.");
cout<<"---------";
system("echo.");
cout<<current_board[2][0]<<" | "<<current_board[2][1]<<" | "<<current_board[2][2];
system("echo.");
system("echo.");
cout<<"Please make a move: ";
cin>>the_move;
system("echo.");
}
winner = winnerz(current_board[3][3]);
};


system("echo.");
system("pause");
return 0;
}


int winnerz(char current_board[3][3])
{

if(current_board[0][0] == current_board[0][1] && current_board[0][1] == current_board[0][2])
  {
  cout<<"You Win Sucker!";
  return 1;
  }
else
  {
  return 0;
  }
}
__________________
&lt;CENTER&gt;<span style='font-size:17pt;line-height:100%'>My Homepage</span>&lt;/CENTER&gt;
dnathe4th is offline   Reply With Quote
Old Oct 11th, 2004, 4:36 PM   #23
dnathe4th
Programmer
 
Join Date: Oct 2004
Posts: 32
Rep Power: 0 dnathe4th is on a distinguished road
aw man, I just tested out that 8000+ line program, its no fun
I had the AI cornered, so it just quit the game
I was X's:
X2O
4O6
X8X

i was gonna win!
__________________
&lt;CENTER&gt;<span style='font-size:17pt;line-height:100%'>My Homepage</span>&lt;/CENTER&gt;
dnathe4th is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:17 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC