Article View: alt.comp.lang.learn.c-c++
Article #212Re: TIC-TAC-TOE in C++ !
From: Jeff Elliott
Date: Mon, 12 Jan 1998 00:00
Date: Mon, 12 Jan 1998 00:00
77 lines
3170 bytes
3170 bytes
Jon, I think actually, 100 lines of code sounds pretty good for a program like this. I hope you've got enough whitespace and comments throughout the code to make it readable and easy enough to follow. I don't suppose you'd mind sending me a copy of the code or posting it here - maybe someone could offer some optimization tips based on what you've already got written. Jeff -- Montgomery, AL, USA Please direct return correspondence to: mailto:cguru@ibm.net NOTE: The opinions and viewpoints expressed herein are the author's own, and in no way reflect those of International Business Machines, Inc. Jon Watson wrote: > > Hey All; > > I am in my second semester of info systems at college and have to write the > age old > program of tic-tac-toe. > > There is a requirement that the program will determine the computers move > as follows: > > The computer is always 'X' > Scan all rows, columns and both diagonals to determine if there are 2 X's > in any one of them. > If there is, place an 'X' in the vacant spot, declare a win and ask the > user if they want to play again. > > If there isn't, > Scan all rows, columns and both diagonals to determine is there are 2 O's > in any one of them. > If there is, still place an 'X' in the vacant spot to block a potential win > by the user. > If neither of these situations apply, generate a random move. > > My question is this: > > I currentl have: > > One loop to search rows for X's > One loop to search columns for X's > One loop to search the diagonals for X's > One loop to search rows for O's > One loop to search columns for O's > One loop to search diagonals for O's. > > This is quite a bit of code. I thought about simply searching the board for > two successive squares > that aren't blank, but that won't work because I don't want it to flag an X > and an O in one row > as a potential win or block, so it seems it has to search for each > individually. > > Finally, the question! Any ideas on how to compact this code so that it > doesn't take up > 100 lines? > > I would also love to incorporate this into the function that searches > whether or not the human has > won based on it's last move, but I think I can handle that myself. > > Thanks in advance! > > Jon > > -- > **************************** > The future is in beta... > ****************************
Technical Details
Message-ID:
<34BADED1.3AB196D7@ibm.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<01bd1f31$0a72dbc0$db4522cf@jwatson>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109fba,750a5b3b86788347 X-Google-Attributes: gid109fba,public X-Google-Thread: 114592,750a5b3b86788347 X-Google-Attributes: gid114592,public X-Google-Thread: 10d4ba,750a5b3b86788347 X-Google-Attributes: gid10d4ba,public From: Jeff Elliott <cguru@ibm.net> Subject: Re: TIC-TAC-TOE in C++ ! Date: 1998/01/12 Message-ID: <34BADED1.3AB196D7@ibm.net> X-Deja-AN: 315419700 Content-Transfer-Encoding: 7bit References: <01bd1f31$0a72dbc0$db4522cf@jwatson> To: Jon Watson <jwatson@freenet.calgary.ab.ca> Content-Type: text/plain; charset=us-ascii Organization: IBM.NET MIME-Version: 1.0 Reply-To: cguru@ibm.net Newsgroups: alt.comp.lang.learn.c-c++,att.lang.c++,comp.lang.c++