Article View: alt.comp.lang.learn.c-c++
Article #210Re: TIC-TAC-TOE in C++ !
From: Craig Richard Sparacino
Date: Mon, 12 Jan 1998 00:00
Date: Mon, 12 Jan 1998 00:00
46 lines
2404 bytes
2404 bytes
In article <01bd1f31$0a72dbc0$db4522cf@jwatson>, Jon Watson <jwatson@freenet.calgary.ab.ca> wrote: >|<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. How about have only three loops... let's say, for arguments sake.. searchRows(*char), searchCols(*char), searchDiag(*char) When you run the function call, simply pass a pointer to an X or an O The function will then search for the given letter. You may need to add three lines to each loop, BUT, you will be able to delete 3 loops. I am passing a char for two simple reasons.. lower overhead, when comparing char, doing so with pointers is easier (and more widely supported) >|<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. Add an if statement to each loop... if there are two O's.. check to see if there is a third. what may be a bit tricky is making sure you stay on the board... e.g.: 1 2 3 if you are checking "2" does the 'puter know 4 5 6 that there is nothing after 3 ? 7 8 9 or, if checking 3, it can't go right anymore... Those are other things to look into, I am not sure if this may be a problem for the simple reason, I haven't seen your code. --Craig -- To appease those that will doubtlessly complain... "The views presented above are those of the author and are not in any way supported or approved of by the University of Delaware; they are instead, my personal attempt to piss you off"
Technical Details
Message-ID:
<69djk7$l96$1@mahler.udel.edu>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: 10d4ba,750a5b3b86788347 X-Google-Attributes: gid10d4ba,public X-Google-Thread: 114592,750a5b3b86788347 X-Google-Attributes: gid114592,public X-Google-Thread: 109fba,750a5b3b86788347 X-Google-Attributes: gid109fba,public From: csparrow@mahler.udel.edu (Craig Richard Sparacino) Subject: Re: TIC-TAC-TOE in C++ ! Date: 1998/01/12 Message-ID: <69djk7$l96$1@mahler.udel.edu> X-Deja-AN: 315268426 References: <01bd1f31$0a72dbc0$db4522cf@jwatson> Summary: Tic-Tac-Toe, C++, pointers, for loops Organization: University of Delaware Newsgroups: alt.comp.lang.learn.c-c++,att.lang.c++,comp.lang.c++