Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Ultimate tic tac toe!

Author
Message
Paynterboi TicTacToe
16
Years of Service
User Offline
Joined: 23rd Dec 2007
Location: That one place
Posted: 29th Aug 2009 01:45 Edited at: 7th Oct 2009 02:44
Tic tac toe you say? that game sucks!

Well my friend, Tic tac toe is a very useful game. It teaches the mind to evaluate every option before making a decision. The most advance tic tac toe players can evaluate the entire game and determine if it will be a cats game or not within the first 3 moves.

But it's for little kid's isnt it? and it's not THAT complicated, I mean, you only get to choose from 9 different boxs..

That is where my new ULTIMATE! Tic Tac Toe comes in. It is a 3d video game that incorporates many different versions of the original tic tac toe! Imagine, Playing tic tac toe on a rubix cube in which you need to be concious of where the peices are all over the cube, one wrong flip, turn, or spin can cause your oponent to win the game! or a 5x5 grid that changes as you put your pieces down. Or try to play the EXTREME TIC TAC TOE GAUNTLET!! and play up to 100 games in rapid succession each lasting a mere 15 seconds!!! and many more!!

Now doesn't that seem interesting??!!

As of the most recent [edit] these are the variations to tic tac toe i have come up with.

Any suggestions on interesting variations to the game of tic-tac-toe apreciated as well.

Rapid-Fire-Tic-Tac-Toe -- players are given 20 seconds to play either 5-10-15-30 games of tic tac toe in rapid succession ( 20 secs per game) scores are tallied and winner's determined at the end)

Rubix Tic Tac Toe -- players place their peices on a rubix cube and can turn the cube to prevent other players from getting points or to help themselves gain points

5x5 Tic Tac Toe -- player X will always go in the middle, It is a little hard to explain but the board will adjust as pieces are placed. ultimately the board will settle on a 3x3 grid ( will write more detailed instructions when I release a working version )

Multi-Dimensional Tic Tac Toe -- players play 3 games of Tic Tac Toe. The tic tac toe games are than stacked upon eachother and players gain points for getting 3 in a row in three dimensions

Cube Tic tac toe -- Much like Rubix ttt but the cube does not rotate and when a peice is played the entire cube belongs to that person (i.e. placing one on a corner puts your peice on three sides)

Custom Tic Tac toe -- pick as many squares to play on and require as many in a row as you want ( i.e. X by X with X in a row )

Tic Tac Toe Race! -- The board is 3 cells in height and the width is 10. The goal is to get 4 in a row going from left to right. The as the board fills up the peices move to the left and the ones on the left fall off the board until a winner is determined.

Falling tic tac toe -- Tetris variation. X's, O's, Wild's, blocks, and specials ( not always good /wink ) fall, get three in a row to prevent the pile from reaching the top.

Sudoku Tic Tac Toe -- a 3x3 grid of 3x3 grids, first person picks a square, a game is played, winner owns the square, cat games turn the square into a wild, second player picks a square and process repeats until either player has 3 wins in a row or the game board fills up, points awarded.


Developement stages:
original:
v1.0 ) Pure text - console program containing original tic tac toe (v1.5 released)
v2.0 ) DarkGDK - 2d version of original tic tac toe (v2.5 released)

This version is almost 100% complete ( needs sounds and checkWin also I may change the backdrop, I like it but I dont know if I want to see it every time I play )

v2.6 will be the Final release for the original version of tic tac toe. It will Feature-
Win Checks
Animations
sound
Menu



5x5 TTT:
DGDK - 2D variation to the original tic tac toe. V1.x releases will be primarily code updates. Once all the required code is complete v2.0 will be the first graphical update and will probably end with v2.6 just like the last version.

v1.4 Released
Playable version-
This version will allow players to place their pieces and block them from playing in restricted cells.


v4.0 will be the 100% final release of the game ( i.e. includeing all releases of all versions tied together in one app with universal sounds and graphical scheme )

[EDIT]
The new ZIP contains
original:
Media
Source
v2.5 tic tac toe
Read Me.txt

5x5:
Media
source
ReadMe.txt
v1.4 5x5 TTT.exe



I'm getting bored with original tic tac toe and I'm sure you all are as well...

Next in line is --
5x5 Tic Tac Toe -- player X will always go in the middle First, It is a little hard to explain but the board will adjust as pieces are placed. ultimately the board will settle on a 3x3 grid ( will write more detailed instructions when I release a working version )

This one will remain in 2d and will consist of it's own custom animations and sounds ( until the very very final release of UTT which will universalize media )

EYE R T3H +ick +ack +oe mester

Attachments

Login to view attachments
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 29th Aug 2009 15:22
Tic-tac-toe is a nice game and your extra ideas sound interesting, good luck in making it. However, your source code and the comments in it show that you are a beginner in programming in C++. I suggest you to learn more about using C++ before dealing with such complicated things as the Windows API or the DirectX SDK. Try to:

- understand the difference between local and global variables,
- understand how function parameters and function return values work,
- consider using arrays and loops instead of defining an individual variable for each cell in your grid (what if you'll have 90 cells in the final game?),
- consider the use of conversion functions to get numbers out of a string.

In several places in the code, you pass global variables to functions, when those variables would be visible to the function without passing them. This would make sense if your purpose were to make sure that the function cannot change the variable, but more often you want to change it inside the function (or in some places, not use it within the function at all).

If you use the same variable name in the function header as the name of a global variable, the result will be that you end up with a LOCAL COPY of the variable with the same name. If you try to change that value within the function, you are changing a local copy, not the global one, so outside the function the global variable never changes. This is called name-hiding. Consider your SwitchPlayer function, where you tried to solve name-hiding by changing the parameter name:



Why doesn't it work if you write playerId (lowercase p) instead of PlayerId (capital P)? Because you create a local copy of the global playerId variable, and you change the local copy, without ever changing the global one. (Returning the new value doesn't help either, because you don't use the return value in your function call.) If you change the first letter to a capital P, what happens is that you define a new local variable in the function header, which is unused, because the rest of the function is using the global variable.

The solution would be to leave out that parameter entirely, if you want to work with global variables. But there is an even simpler way. If you want to switch from 1 to 2 and back, instead of the whole function you can just write this:




Other things: Pay attention to compiler warnings. When compiling your code, the compiler gives several warnings:



This is because in the CheckWin function you have such lines:



The "winId == boxId" will not change winId because this is a condition, not an assignment.



You can't return two values from one function like this. This compiles only because comma is an operator in C++, so this has some meaning for the compiler. I must admit that I never learned the subtleties of the comma, I think it will always return the second value. In any case, you'd better stick with one return value.

I hope this helps somewhat.

If you still want to use the Windows API, there is a good basic tutorial here: http://www.winprog.org/tutorial/
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 29th Aug 2009 20:13
Quote: "I must admit that I never learned the subtleties of the comma, I think it will always return the second value."


That is correct. The comma can be quite useful but to my thinking it's used mostly for non-standard hack. I've used it for force some side effects that I didn't want to incorporate in the body of a loop, like incrementing two variables at one time while testing for the value of only one.

do {
blah(j);
} while (j++, --i);

Increment j while also decrementing i until i drops to zero. The second expression is the only one tested but both side effects take place.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Mista Wilson
16
Years of Service
User Offline
Joined: 27th Aug 2008
Location: Brisbane, Australia
Posted: 29th Aug 2009 23:59 Edited at: 30th Aug 2009 00:00
The comma operator is used just as you said Lilith, except its not actually forcing the compiler or hacking it or anything, its how its meant to behave

The following is a valid and very useful loop :



(its actually pasted from my terrain system and is the initial part of the build process, filling in vert data from the heightmap)

The idea is that you can increment 2 or more variables at the same time, saving the need to declare a variable outside the scope of the loop of you dont need to.... (otherwise, if you need to have another incrementer you would have to declare it outside the loop and increment/check it inside the loop)

Ok, sorry for being off topic there lol...

@Paynterboi - Your idea sounds very interesting. I wouldnt mind seeing a tic tac toe game like that, I hope you have fun building it and learning GDK along the way

EDIT : ignore the indentation errors.... seems my ctl-v paste doesnt like to do what it should sometimes lol

If it ain't broke.... DONT FIX IT !!!
Paynterboi TicTacToe
16
Years of Service
User Offline
Joined: 23rd Dec 2007
Location: That one place
Posted: 30th Aug 2009 04:36 Edited at: 10th Sep 2009 01:05
@mireben I am an extreme newbie to c++ but dont discredit the fact i made a workin game! lol

anyway..
Quote: "
In several places in the code, you pass global variables to functions, when those variables would be visible to the function without passing them. This would make sense if your purpose were to make sure that the function cannot change the variable, but more often you want to change it inside the function (or in some places, not use it within the function at all).

If you use the same variable name in the function header as the name of a global variable, the result will be that you end up with a LOCAL COPY of the variable with the same name. If you try to change that value within the function, you are changing a local copy, not the global one, so outside the function the global variable never changes. This is called name-hiding. Consider your SwitchPlayer function, where you tried to solve name-hiding by changing the parameter name:

+ Code Snippet:

"

I slapped my forhead reading this because I knew that which is why some of the checkwin functions dont work...

Quote: "playerId = 3 - playerId;"

this is clever wish I thought of it.

Quote: "If you still want to use the Windows API, there is a good basic tutorial here: http://www.winprog.org/tutorial/ "


@Lilith
if you are refering to the main loop, i'm not sure how what you said applies to it but the purpose was to create a loop that wouldn't terminate without user input

@Mista
your "off topic" comment was still useful, helped me learn something new 8-D thanks. I had a game identicle in dbpro but it was lost when I installed vista onto my computer, i forgot about my precious. But it didnt have nearly as many features. It was basicaly a cube you played tic tac toe on and each side was evaluated for points, you also recived points for doing things such as 1) putting your peice in the middle of each side 2) getting 3 in a row starting on one side and ending on another etc..

Taking advice from Mireben I'm going to take another look at my original code to become more familiar with c++ and maybe incorporate some new features into it.. out of curiousity did any of you play? if so did you try the admin comand? and if so did you type lolwtf? for the pw (if you cheated and read the source dont tell lol i got bored)

EYE R T3H +ick +ack +oe mester
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 30th Aug 2009 11:16 Edited at: 30th Aug 2009 11:17
Quote: "dont discredit the fact i made a workin game! l"


It was not my intention at all to discredit you, we all started somewhere. The intention was to help.

Quote: "you dont get explinations like this in the tutorials i've looked at."


True, the online language references are very useful, but maybe not as lengthy on explanations as a textbook. Here are the links to the references I know of, just in case you haven't yet discovered all of them:

http://www.cplusplus.com/doc/tutorial/
http://msdn.microsoft.com/en-us/beginner/cc305129.aspx
http://www.learncpp.com/

Quote: "did any of you play?"


Well I tried, but the program has a serious problem, which I even forgot to mention yesterday. Most of the time when it is started, especially if other windows are behind it when it starts (like in debug mode from Visual Studio, or from a file manager window), it is rapidly blinking and totally freezes the computer, putting about 100 instances of "conime.exe" into the task manager. (According to internet sources, this process is related to console applications.) Haven't you experienced this on your computer?

I can only guess at the source of the problem: Your main procedure (int WINAPI WinMain) looks like a Windows API main function, but you don't create any window, instead you use console commands like cin, cout, cls... I don't know how well these go together. The main function of a console application looks different. I would suggest that, as long as you don't use any Windows GUI elements, create a new project in Visual Studio, taking care that it's a console application, and transfer your existing code there.
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 30th Aug 2009 11:49
P.S. The one time when I managed to start the program, it worked well, except that it didn't recognize the win, but you already listed that as a known bug.
Paynterboi TicTacToe
16
Years of Service
User Offline
Joined: 23rd Dec 2007
Location: That one place
Posted: 30th Aug 2009 22:55 Edited at: 30th Aug 2009 23:07
um.. as far as the lolwtf? pw goes if you type it it will open about a hundred cmd.exe windows maybe that code has something to do with it. as far as the winapi main loop it was because i was going to bring it into the win api but the only thing i do is create a popup welcome box in that version.

try commenting out the messagebox() and changeing the loop to the regular main() instead of WinMain() and see if that helps?

also, that "Dont discredit" comment was more of a joke 8-P
Quote: "Quote: "you dont get explinations like this in the tutorials i've looked at."

True, the online language references are very useful, but maybe not as lengthy on explanations as a textbook. Here are the links to the references I know of, just in case you haven't yet discovered all of them:
"

I also have a c++ for dummies book XD

[edit] if not, erase the part of the admin function that accepts lolwtf? as a valid PW that whole block of code may be what is causeing it to load up all the random programs

EYE R T3H +ick +ack +oe mester
Paynterboi TicTacToe
16
Years of Service
User Offline
Joined: 23rd Dec 2007
Location: That one place
Posted: 3rd Sep 2009 01:16 Edited at: 5th Sep 2009 08:43
A couple things I missed.

@Mireben

Quote: " -consider using arrays and loops instead of defining an individual variable for each cell in your grid (what if you'll have 90 cells in the final game?),
- consider the use of conversion functions to get numbers out of a string."


I dont use arrays and loops in this version only because I only have 9 cells and as you pointed out I am still new to c++ (i do have experience useing loops and arrays in DBPro so it's not a new concept (well not totally new))

Also, I could use conversion functions but esestially I'm only making the code longer because the way it is set up now the input it recieved as an integer. An input of 1i (although not intentional) is discarded and I do know of a function that will pull the 1 out and discard the i but I guess i just didnt want to use it.

The error you experienced while trying to run the program in the vc++ debug eviroment (i'm just guessing here) may be due to the fact the .exe's i upload are compiled from the devc++ IDE so that they can be run on any computer that does NOT have vc++ express or it's runtime.

[edit] it occured to me that you were probably compiling the source in vc++ and than useing the debug enviroment and if that is the case, disregard the former.

EYE R T3H +ick +ack +oe mester
Paynterboi TicTacToe
16
Years of Service
User Offline
Joined: 23rd Dec 2007
Location: That one place
Posted: 6th Sep 2009 23:36 Edited at: 7th Sep 2009 07:53
I need to know the x and y locations of the topleft and bottom right of my sprites using the DGDK. I can easily do this via math and that isn't really the issue. What I'm interested is why this code doesn't update? It will show the x/y of the mouse when the program is run but will not update..



also is there an index of all of the DGDK commands like there was in DB and DBPRO?

[edit] Another issue I ran into:

This is the source so far...



Essentially, the purpose is so that when one of the empty box's is clicked it will display an X or an O in the appropriate box. It places the X's and O's in the correct box just fine. The issue is that the playerId variable changes so fast that there is no gaurentee that the x's and o's will alternate appropriately if that makes sense. Is there a way to prevent the loop from repeating until the mouse is clicked?

EYE R T3H +ick +ack +oe mester
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 6th Sep 2009 23:50
You need to bring the assignments of your mouse positions into the top of your loop. They're only updated when you make the assignment by function calls.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Paynterboi TicTacToe
16
Years of Service
User Offline
Joined: 23rd Dec 2007
Location: That one place
Posted: 7th Sep 2009 00:11
@lilith
Thanks that makes sense 8-P

EYE R T3H +ick +ack +oe mester
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 7th Sep 2009 12:46
There is no way to "stop the loop" (well, there might be with some dirty trick, but you hardly want to stop display update completely). But you don't have to change that playerID every loop. Keep in mind that the loop to update the display, and the turns of the game when one player takes over from the other, are not the same events. Write the code so that the playerID only changes when a player has successfully placed a piece on the board.

Also, using the dbStr function without deleting the returned string causes a memory leak. (I still wonder why such an important information is not in the help.) It's OK for testing, but for a final program, it's better to use sprintf with a character array.
Paynterboi TicTacToe
16
Years of Service
User Offline
Joined: 23rd Dec 2007
Location: That one place
Posted: 7th Sep 2009 23:10 Edited at: 10th Sep 2009 00:59
How do you delete the returned string? Also I made a few alterations to the code so that for the most part the turn changes approriately but your method would be more efficient...


this seems to work as long as you dont accidently click a used square or the black space..

I just finished making the adjustments you suggested and this is the complete code up to this point



It works proporly now, My next step is to create a newgame function that resets all the boxs[ ] to 0, resets the sprites to image 1, and sets the playerId to 1..

NewGame()..


And add this to the bottom of Play()



Is there a way to change the directory to load the images from? as it is the images must be in the same directory as the exe. I would like to have them in a folder labled "media" or something to help organize it a little better.

Also, I think that in the long run I will make many versions of tic tac toe and have them all be separate programs. But I will make one prgram that can launch the one that somone wants to play if that makes sense. Is there a way to code it so that it will launch other applications?

I notice that in some of the samples there are animated sprites in the format of .png and .bmp, is there a good tutorial on how to create images that can be used as animated sprites?

Is there a way to replace the cursor with a sprite so that I can use sprite collosion instead of x/y coordinates to determine what the players are clicking on?

When I click on a cell it will both place my piece and tell me that the box is being used already ( I assume it is again because the loop runs multiple times within one click of the mouse ) Eventually i will have a sound play instead of a message but I dont want the sound played at the same time a player attempts to place a piece. Any suggestions?

[edit]Refer to the original post for downloads...

EYE R T3H +ick +ack +oe mester
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 8th Sep 2009 17:34 Edited at: 8th Sep 2009 17:40
Quote: "Is there a way to code it so that it will launch other applications?"


Try dbExecuteFile or ShellExecute.

Quote: "Is there a way to change the directory to load the images from?"


dbCD command to change the working directory, or include the path into the file name that you load.

Quote: "How do you delete the returned string? "




But it's easier on the long run to use sprintf. Define a char array (just once as a global variable) and you can use it for formatted printouts:



Quote: "is there a good tutorial on how to create images that can be used as animated sprites?"


I don't think there is a tutorial on that. Creating graphics is rather an art than something that can be taught.

P.S. The code looks much better now than your first attempt, although I'd try to optimize it a bit more, by calculating the box positions from the box number and the box size, instead of hardcoding the pixel values. That would have two advantages: box size would be easy to change, and the large "case" structures which have repeated code could be simplified. (EDIT: question of style, I usually try to parameterize and generalize even the smallest programs, thinking of making further development easier.)

P.S.2
Quote: "Also, she couldn't locate the v2.0.exe so i created a shortcut to it in the main directory...Women..."


No wonder she couldn't locate it if it's not there. In the uppermost directory in that zip file, you have all kinds of EXE versions except for 2.0, and the latest version is hidden in subdirectories and doesn't even contain the version number. (Hey I'm a woman too, plus a programmer who knows that end-users don't like even the smallest difficulties, like having to search for something.) Also, if you want to give a program to somebody else, then you should compile it in release mode and give away just the latest executable + media, no need to package the whole large debug directory and the project ncb file (14 MB in itself) with it. It increases the download size and it is not needed to run the program.
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 8th Sep 2009 17:45 Edited at: 8th Sep 2009 17:45
I left this out of the above post:

Quote: "Is there a way to replace the cursor with a sprite so that I can use sprite collosion instead of x/y coordinates to determine what the players are clicking on?"


I believe the usual way is to make a sprite which always follows the mouse movement and then hide the mouse cursor (dbHideMouse).
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 8th Sep 2009 23:00
Re-reading the posts above - I hope what I said about finding the EXE was not offensive. I was just trying to illustrate why it would be difficult to find for someone who is not proficient with computers, provided that she saw the same directory structure as what you uploaded here. Users are not always experts and the programmer should try to make life easy for them if possible. The shortcut, for example, was a good idea.
Paynterboi TicTacToe
16
Years of Service
User Offline
Joined: 23rd Dec 2007
Location: That one place
Posted: 9th Sep 2009 00:32
@ mireben
Quote: "No wonder she couldn't locate it if it's not there. In the uppermost directory in that zip file, you have all kinds of EXE versions except for 2.0, and the latest version is hidden in subdirectories and doesn't even contain the version number. (Hey I'm a woman too, plus a programmer who knows that end-users don't like even the smallest difficulties, like having to search for something.) Also, if you want to give a program to somebody else, then you should compile it in release mode and give away just the latest executable + media, no need to package the whole large debug directory and the project ncb file (14 MB in itself) with it. It increases the download size and it is not needed to run the program"


I was telling her the exact name of the exe and exactly where it was and she couldn't locate it. Also it was more of a joke I love her to death and love women in gneeral no offense intended.

As far as the sprites go, I was aware of the code my question was more so how do I create an image ( of any quality ) to use an an animated sprite such as creating a sprite sheet, I know that you create individual tiles but it seems to me that there is something missing otherwise how would the GDK know where the frame begins and ends?

How do I tell vc++ to compile into release mode?

What about custom icons? how would I go about making them?

Thanks for your info it was very useful

EYE R T3H +ick +ack +oe mester
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 9th Sep 2009 00:41
Quote: "how would the GDK know where the frame begins and ends?"


You tell it how many frames are across and down. The animation assumes that the frames are evenly divided across width and height so can determine what rectangles to render.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 9th Sep 2009 10:26 Edited at: 9th Sep 2009 10:48
Quote: "How do I tell vc++ to compile into release mode?"


On the toolbar on top, next to the green button which runs the program, there is drop-down list which shows "Debug". Just change that to "Release". It creates another directory in the project, that's where you find the new EXE. (Usually it should be smaller because the debug info is left out of it.)

The debug and release modes also have their own configuration settings in the project "properties" dialog, but they should be OK by default, only if you have any special settings for the project, like additional include libraries, then they need to be set up in both modes.

Here is a thread about changing the window icon:

http://forum.thegamecreators.com/?m=forum_view&t=151334&b=22

EDIT: The Windows API tutorial that I mentioned in my first post also talks about changing the icon.
Paynterboi TicTacToe
16
Years of Service
User Offline
Joined: 23rd Dec 2007
Location: That one place
Posted: 9th Sep 2009 22:11 Edited at: 13th Sep 2009 06:24
@lilith
That helps thank you. Now I can make cool animated x's and o's so the game isn't so blan.

@mireben
I know how to change icons using Window.h but I don't know how to change it using DarkGDK (well didn't until I read the forum you linked to). I'm interested to know how I would go about using the Windows API AND DarkGDK in the same program if that is possible, it would provide some more options as far as making the game goes.

I'm Currently on a School computer so I cannot recompile the game in release mode but I will do that after I get home in an hour to reduce the download size. Also I have some bad graphics incorporated into my game that I will upload as well. The new zip will also be organized in a way that is easier to understand.

I'm sure I can figure out how to do sounds for my game on my own but I still need help figuring out how to prevent the sound indicating that you cannot place your piece on a square that is taken from playing at the same time you click to place your piece on an empty square.

[EDIT] The new download has been posted back on the first post

[EDIT] I am having troubles with getting the animated x and o images to play properly, I want the animations to play only once, when the box is clicked and to show the last frame of the animation for the rest of the game ( until the game exits or the newgame button is pressed ).


Attached is a full copy of the source, all the required media, and an exe compiled in release mode. Only the first 2 squares have the code involving the new animated sprites so the other 7 will simply disapear when clicked which is expected. It is the intent to replace the newgame button with a menu button and to also incorporate a menu before the game begins. The menu will consist of begin or exit until an AI is implimented or once I add new features either way. I will work on the code for that until this issue is resolved.

thanks!

[edit] removed upload

EYE R T3H +ick +ack +oe mester
Paynterboi TicTacToe
16
Years of Service
User Offline
Joined: 23rd Dec 2007
Location: That one place
Posted: 10th Sep 2009 22:09
I dont remember where but I remember being told that 3d is faster than 2d? any way I was wandering what the benefits of useing 3d as opposed to 2d would be if any?

EYE R T3H +ick +ack +oe mester
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 12th Sep 2009 12:59
A few tips for you again.

I like your graphics, but I commented out the animated background immediately because it hurts my eyes. If this will be a feature for the finished game, I suggest to make the animation very slow and smooth (with more frames).

The dbPlaySprite function will not be quite suitable for your animated X and O cells, because that function must be continuously called every loop to make it work. (Just like you did with the animated background.) If you want to display the animation once and then stop at the last frame, use dbSetSpriteFrame, alternating with dbWait commands, to display each frame just for a specified amount of time. It's not a long code with only 4 frames but it can even be placed into a for loop.

I suggest to get rid of repeated code. For example in the Play() function you have 9 if branches for each sprite. Wouldn't it be simpler like this?



In the same way, the PlacePiece() function can be simplified as well. As you are adding more features, like animation, sound, etc. you will have more and more repeated code. It's not only inelegant and tedious for you to write, but gives rise to copy-paste errors. Generally, if you have code which is largely the same whichever option is chosen, you want to get it out of the switch. This will also solve your problem of where to put playing the sound. You can use the following structure as a basis, for example:



Notice that by simply deducting one (or whichever number is the first sprite) from the sprite ID, you can directly index the box array, and you only need to write all animation and sound commands once. The only hurdle is to determine the sprite position, but that can also be done by calculating position from sprite index and width/height. It should even be possible to position the animated sprites by querying the position of the corresponding non-animated sprite (dbSpriteX, Y) and then you don't need any math here.

The NewGame function needs some improvement too, because the animated sprites which have been placed in the previous game are not hidden when you start a new game.

The next tip is mainly a question of style, so I just call your attention to the possibility and you use it or don't. As the game gets bigger, it will be more and more difficult to work with hardcoded sprite ID numbers, because you have to remember what is what. Usually I begin the program with defining constants for ID numbers, in your case it could look like this:



I specified only the base, not all 9 sprites, because the rest of the numbers are easy to get from the base. Within the enum range, the numbers increase by 1 if you don't tell the compiler to use some other number, so after idAnimBackdrop, the other two numbers will be 12 and 13.

The advantage is that ID ranges are easy to change and there is no danger of accidentally using an already occupied number for something else. Different enum ranges can be defined for different types of objects that Dark GDK allows to have overlapping ID numbers, for example idImages, idSprites, id3DObjects.

It is possible to use Dark GDK and Windows API together. You can't place API elements into the graphic of course, but pop-ups (file open/save dialog, colour chooser, message boxes, dialog boxes) are possible any time. Modeless dialog boxes are also relatively easy. In addition to the API tutorial which I already mentioned, there is another tutorial (credit Sephnroth), which shows how to include a menu into a Dark GDK window and how to exchange the window callback function to make the menu work. You can get it from this thread (links in his original thread seem to be broken but this still works):

http://forum.thegamecreators.com/?m=forum_view&t=137633&b=22

Mista Wilson has even figured out recently how to put a Dark GDK window into an MDI application:

http://forum.thegamecreators.com/?m=forum_view&t=152825&b=22

So the possibility is there but it's certainly time-consuming to get the API elements to work correctly.
Paynterboi TicTacToe
16
Years of Service
User Offline
Joined: 23rd Dec 2007
Location: That one place
Posted: 13th Sep 2009 01:53 Edited at: 17th Sep 2009 00:36
Quote: "A few tips for you again."

I Really appreciate the help you and lillith have been giving me and the one comment mista made. I know that it seems like most of my questions are DarkGDK related but you guys have been teaching me alot about c++ in general as well.

Quote: "I like your graphics, but I commented out the animated background immediately because it hurts my eyes. If this will be a feature for the finished game, I suggest to make the animation very slow and smooth (with more frames)."


I theorized the backdrop would cause physical pain but it didn't bother me XD. I dont intend to create the final graphics for a while still it just looked cool and I was bored but thanks for the props on the graphicz.

Quote: "dbSetSpriteFrame"


I'm going to look this up in the header files.

Quote: "I suggest to get rid of repeated code. For example in the Play() function you have 9 if branches for each sprite. Wouldn't it be simpler like this?

+ Code Snippet

In the same way, the PlacePiece() function can be simplified as well. As you are adding more features, like animation, sound, etc. you will have more and more repeated code. It's not only inelegant and tedious for you to write, but gives rise to copy-paste errors. Generally, if you have code which is largely the same whichever option is chosen, you want to get it out of the switch. This will also solve your problem of where to put playing the sound. You can use the following structure as a basis, for example:

+ Code Snippet"


I under stand this however, I have been coding it the other way because it is something easier for me to read. The final stage is going to be things like code optimization. Once I get past the first 2d version I expect this forum to be relatively quite until I begin coding the 3d versions of the game I will begin to use as many different commands for 3d coding until the first 3d one is completed ( that's why I'm still working on v2 as opposed to moving onto another 2d version)

As for the enum idea, until the most recent version which isn't uploaded, I had no idea what an enum was. But I did some research on some of the sites you showed me a while back and I used enum to define game modes for a menu, new game, and game.

The API question was more of a curiosity than anything else but in appreciation of your help and simply to learn I will spend some time ( when I'm not on my gf's comp ) to go over those threads.

Quote: "The NewGame function needs some improvement too, because the animated sprites which have been placed in the previous game are not hidden when you start a new game."


I had already fixed this, the most up to date version isn't uploaded due to the lack of animated x's and o's which is going to be fixed thanks to you .

Thanks for all the help again!

[edit]
Please read the latest update to the original post. It contains the most up-to-date version of original tic tac toe as well as information regarding the begining of the first variation.

EYE R T3H +ick +ack +oe mester
Paynterboi TicTacToe
16
Years of Service
User Offline
Joined: 23rd Dec 2007
Location: That one place
Posted: 17th Sep 2009 01:50 Edited at: 17th Sep 2009 07:13
[EDIT] This post originally had quite a bit of code snippets I was having trouble with but when I put the code onto my laptop and compiled everything compiled perfectly w/o being edited. Sorry for the post. I will edit my next questions here so I don't Make another unnecessary post.

[EDIT]
I have this code to determine the distance between the box clicked and all used boxs, if the distance is greater than 2, the box is out of range. The maths are all accurate it just returns an error i'm not familliar with and that I couldn't understand useing the MSDN site.

note: trindex read as index of test/clicked row/collumn


returns these errors



any suggestions?

EYE R T3H +ick +ack +oe mester
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 17th Sep 2009 22:34
float cc, cr, i, j;

You use these variables as array indexes, but you can't index an array with floating point numbers. Only with integers.
Paynterboi TicTacToe
16
Years of Service
User Offline
Joined: 23rd Dec 2007
Location: That one place
Posted: 18th Sep 2009 07:12 Edited at: 19th Sep 2009 18:59
Thanks, I got home and opened the code to make the changes but my back has been having nastey spasms all night and i just need to go to bed so i'll have to update the thread tomorrow.

[EDIT]
Here is what I have regarding setting up the grid...


(sorry for the wonky tabs, looked better in vc++e)

Is there a way to loop the sprites?

Also I set up this function to display the values of the above mentioned boxsD[][][] but it doesnt display



EYE R T3H +ick +ack +oe mester
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 20th Sep 2009 12:56
Quote: "Is there a way to loop the sprites?"


Sure:



I haven't tested it but it should work.

Quote: "I set up this function to display the values of the above mentioned boxsD[][][] but it doesnt display"


First, if you do a dbSync every time after a print, it will delete the previous print. The dbSync should only be called when you have done all your prints for the current frame.

Second, that array contains integer numbers as far as I can see from the code. dbPrint will print only text and it won't convert automatically for you. Do a number to text conversion.
Paynterboi TicTacToe
16
Years of Service
User Offline
Joined: 23rd Dec 2007
Location: That one place
Posted: 21st Sep 2009 09:03 Edited at: 5th Oct 2009 23:47
Quote: "Second, that array contains integer numbers as far as I can see from the code. dbPrint will print only text and it won't convert automatically for you. Do a number to text conversion."


I may not have uploaded the newer code but the array actualy conatins floats now ( sqrt() doesnt accept ints ). Also the dbPrint command says it accepts double, long, or LPSTR ( and yes float is not among these ) but when I attempted to use the idea here:

http://notfaq.wordpress.com/2006/08/30/c-convert-int-to-string/

I only got errors when compileing. And I changed the type to double ( accepted by both dbPrint and sqrt() ) and the code compiled but failed to print the nessicary info.

Source as it is now ( I havn't worked on it at all the past few days too much RL stuff ).

EYE R T3H +ick +ack +oe mester
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 21st Sep 2009 20:53
Sorry, the help doesn't say that dbPrint accepts numbers, so I didn't know about it. I always use dbText because you can give it coordinates.

I only have these guesses why the print does not work: either the coordinates are not good and the print is out of screen, or maybe the print is under the background sprite. Try disabling the background image.

For printing debug text containing numbers, have a look at the sprintf function, it is easier than the stream method given on that web page:

http://www.cplusplus.com/reference/clibrary/cstdio/sprintf/

Once you have a formatted string in a character array, you can give the char array as a parameter to dbPrint or dbText.
Paynterboi TicTacToe
16
Years of Service
User Offline
Joined: 23rd Dec 2007
Location: That one place
Posted: 22nd Sep 2009 00:43 Edited at: 5th Oct 2009 23:48
First, the printing of the data isn't 100% nessicary other than to reassure me. I ran through the for loops on a piece of paper to determine which value was placed where and it worked out fine.

@mireben
Quote: "either the coordinates are not good and the print is out of screen, or maybe the print is under the background sprite. Try disabling the background image."


The coords are good ( can't be wrong with 0,0 ) and I had already attempted commenting out all the sprites pasted to the screen.

As of right now I'm lazily putting off continueing with the code because the next part will require a bit more effort on my part.

I'm trying to determine a way for tell the game where to paste the sprites (blocky.bmp and blockx.bmp) that will visually show which cols / rows cannot be used. The distancefrom function prevents players from playing out of range but without a visual the game will rely specifically on whether or not the players understand the logic which we all know that not all users will. I pondered the idea to use the distrancefrom function to determine this but the only way I can imagine that working is by testing distances from x to x (without incorporating the y's ) and y to y. My only concern with that is that it will require the hard codeing of specific test points and the game will ultimately be testing from at least 8 points every time a box is clicked. The reasons this conerncs me are 1) processing time 2) bad code design.

below is an example:



I'm sure you can see how this gets annoying. ( note I didnt put too much effort into the code above, it was typed streight into the post. The coords I'd be testing above may not be the actual test coords and the statements may not be structured correctly but this gives an idea of the repetitiveness of codeing via this method )

I concidered for loops that would just test distance form everything and place accordingly but that just amplifys the first concern with the previous method.

Another method I considered was to create a way to specify that if I clicked in this row / col than these rows / cols would be un-usable ( same as distance from method but without codeing in the maths, presents the same concerns )

I guess my question is:

Is there a way to impliment this logic:
1) Cannot place piece more than 2 cells from the center cell ( x_x_x)
2) cannot place piece more than 2 cells from the cell furthest form the center cell ( x_xo )

[EDIT]
After posting the above, I used your Idea for looping the sprites and the images don't display. Also, the most up-to-date source I have incroporates the same enum of game modes. I have only worked my way past the new_game, and play_game values for g_mode and as such I placed a default at the bottom of the switch case. The way the game is setup right now, the default case should never be called. The new_game value works perfectly ( except the fact the for loop provided didn't work ) and the playgame appears to be flawless as well. When compiled with a default label the program tells me that the default label blocks the initializations of my mx and my variables and I do not understand why this is. ( source attached ).

EYE R T3H +ick +ack +oe mester
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 22nd Sep 2009 21:28
I'm sorry that my recent comments were not so useful. I'll have a look at the latest code and see if I can give better help, it just takes a little time.
Paynterboi TicTacToe
16
Years of Service
User Offline
Joined: 23rd Dec 2007
Location: That one place
Posted: 23rd Sep 2009 06:50 Edited at: 23rd Sep 2009 06:54
@mireben read the entire thread, you are by far the most useful person who has posted here I'm in no hurry otherwise I would have a nearly completed code that looks like crap ( like my first game that you were kind enough to insult ( j/k i apreciate your help with it ) )

I got an Idea, I'll make a list of everything you tought me:
Creative ways to use maths for looping
Enumerations
How function params create local variables
Importance of elegant code
Arrays can only be indexed by ints
Quite a bit of help regarding GDK specific commands
Useful online references
And you indirectly made me look up my own answers ( cause I felt guilty for askin so many questions ) which helped me learn alot as well

To be fair:

@mista
Use of comma's in do/while loops

@lillith
Use of comma's in do/while loops
Help with understanding how animated sprites work in DarkGDK
Help with GDK specific commands

You guys have tought me so much that I was able to get permission from the instructor of the C++ courses at my College to skip C++ 1. I guess I'm trying to say that this forum has been useful to me in ways you guys probably didn't expect and I thank you.

Hopefully this game will teach me more advance topics as well such as the uses of data structs ( I know syntax but I havn't yet found a use for them ) unions,and well, basically everything on this list:
http://www.cplusplus.com/doc/tutorial/
below pointers ( about half the tutorials )

EYE R T3H +ick +ack +oe mester
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 23rd Sep 2009 23:44
Now I can answer at least two of your questions. First, I tried the sprite-pasting loop and the images do appear. See the attached image, is that what you are supposed to see? The only problem was that three image files (including the empty cells) were missing from your latest zip file, so I had to copy them from one of my earlier backups of your files, don't know which. Anyway, isn't the problem simply that you have accidentally deleted these images from the media directory?

EmptyCell.bmp, XCell.bmp, OCell.bmp

The other question, why compilation fails if you have a default branch. I'm not surprised at that, but I'm surprised that it does not fail if you don't have a default. Anyway, what the compiler is telling you is this: if the execution of the program turns out so that the default branch is executed, then the mx, my, mc variables will never be initialized. This is completely true. If you want, you can get around this error message simply by placing brackets around the whole case branch:



This should compile because it creates a block within which the variables are used and the compiler won't look for them outside the brackets.

As to the distance calculation question, I'll get to that later.

Attachments

Login to view attachments
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 23rd Sep 2009 23:48
P.S. If you have a PlayGame function anyway, another way of solving the compiler's complaints is to transfer the whole mouse coordinate handling into the PlayGame function and then the mx,my,mc variables will be local to the PlayGame function and not defined in the switch.
Paynterboi TicTacToe
16
Years of Service
User Offline
Joined: 23rd Dec 2007
Location: That one place
Posted: 25th Sep 2009 06:46 Edited at: 5th Oct 2009 23:47
I just moved the delarations to the global section...

I figured out why my images werent displaying. The set color key for some reason was making black transparent when it was in this function...


But when i moved it to the begining of the void darkGDK ( void ) function, it worked fine however!!!! The image that was than displayed was ( attached ).

The image labled "image" is the example the others are the images used in this game ( until i remake them ) and the source is also included.

[Edit} i realized the setupwindow() was never called.

EYE R T3H +ick +ack +oe mester
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 26th Sep 2009 16:15
First of all, something I forgot last time:

Quote: "I was able to get permission from the instructor of the C++ courses at my College to skip C++ 1."


Congratulations! That's a good progress indeed.


Nice that you worked out the images. It's weird that the colour key setting works in another place in the program.


Returning to the distance calculation questions. The reason why I didn't answer for so long is that I simply don't understand the question. I thought maybe I'd understand reading it when I'm less sleepy, but didn't manage. Let's see the rules:

Quote: "
1) Cannot place piece more than 2 cells from the center cell ( x_x_x)
2) cannot place piece more than 2 cells from the cell furthest form the center cell ( x_xo )
"


If the whole grid is 5 rows and 5 columns, then it's impossible to place a piece more than 2 cells away from the center cell. Not in the same row or column, anyway. How you calculate the diagonals is another question. I must say that using square root distances in a grid-based game sounds rather strange to me. And what is the "cell furthest from the center cell"? Those are the four corners, right? But if you can't place a piece too far from the center and not too far from the corners either, there are only 4 cells left in the whole grid which are allowed.

It would be good if you could provide a graphical explanation of the rules.
Paynterboi TicTacToe
16
Years of Service
User Offline
Joined: 23rd Dec 2007
Location: That one place
Posted: 28th Sep 2009 22:45 Edited at: 29th Sep 2009 07:14
[EDIT]
I had graphical instructions until I remembered that my site doesnt support direct linking to the images. I created instructions at:

Http://www.picasoe.iwarp.com/programming/5x5TTT.html

I created this code to test the distance formual to determine whether or not the logice in the game work useing the distance formual and to display the coords stored in each boxsD[][][].



There is some bad indentation and such but it appears that all the coords are correct and the distance formual works correctly however the logic is going to be changed:

The original rules state that:
1) no piece can be placed further than 2 cells from the center cell
2) no piece can be placed further than 2 cells from the furthest used cell from the center.

The logic must be changed to:
1) each piece must be placed less than 3 cells from the center cell
2) each piece must be placed less than 3 cells from the furthest used cell from the center.

even this wording needs some changes ie less than 3 cells is 2 cells but it is more or less to help understand that when codeing we will be using <3 not >2.

Sorry for typos did this quickly cause my gf is trying to make me do my homework.

reason being the distance between the bottom left and top right ( or top right / bottom left ) comes out to 2.82843.

EYE R T3H +ick +ack +oe mester
Paynterboi TicTacToe
16
Years of Service
User Offline
Joined: 23rd Dec 2007
Location: That one place
Posted: 30th Sep 2009 05:09 Edited at: 30th Sep 2009 05:10
I have begun to code the function to visually restrict the un usuable cells by testing the clicked cells distance from test cells. I am still tossing around the idea on whether or not to simply say that if cc = 0 than block cols 4 and 5 as opposed to testing distance from specified cells.

EYE R T3H +ick +ack +oe mester
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 1st Oct 2009 22:56
Thanks for the graphical explanation, it made the rules clear.

I'm still saying that you don't need square root calculation. When you say that a cell cannot be placed "more than 2 cells away" from another cell, what this means is that its distance in either the X or in the Y direction (or both) cannot be more than 2 cells, and the result is a rectangle. The pictures confirm this. If you calculate square root distance, then you are actually making a circle instead of a rectangular area, and if you try to fit this to a grid, things get complicated. What you need instead is a simple difference calculation between row and column indexes. Here is how I would imagine the game design.

First, you place the center piece on the grid. Either it is automatically placed by the program, or one of the players places it, in any case you have the starting row (R) and column (C) indexes, which are actually indexes in your box array as well. Note that I try to use row and column instead of X/Y, because it can be confusing that row is Y and column is X.



At this point, you should check the board to see which cells are blocked already. If you start with a 5x5 grid and the center cell is in the middle, there is nothing to check, so you can skip this step. But if the grid is bigger, then a first check is necessary: block all cells which are further away than 2 cells from the center (in either direction). In the code below, MaxRows and MaxColumns are the size of the grid.



How you indicate that the cell is blocked is up to you. In addition to displaying a sprite at the corresponding position (which is easy to calculate from the row/column and the sprite size), you might want to set a flag in the box array as well, which can be useful later if you need to check the status of the cell.

This check needs to be done only once, since the center cell does not change during the game.

We need other variables to store the distance of the "farthest cell from the center". When the game begins, such cell does not exist yet - or, saying it another way, it is the center cell itself. So the "farthest distance" we found so far is zero:



Then the player clicks somewhere to place a piece on the board. From the mouse coordinates, calculate the row/column indexes of the cell that the player clicked.



Note that this is integer division. The result will give the row/column indexes starting from zero. If you check sprite collision, you may skip the validity check because you know that the player must have clicked in a good place if the mouse collided with certain sprites. Otherwise, you need to check if these are valid array indexes (within the grid) and if the cell is free or blocked, so:



Now that we have a new piece on the grid, it is time to check if this is farther away from the center than any other so far. If yes, then store the new maximum distance, then re-check the board to see if we need to block any cells which are too far from this cell. The board is re-checked even if the new cell has equally far coordinates. This is to take care of the special case on the picture before last in your graphical rules, which shows two "farthest cells" at equal distance.



You may or may not need the "this_cell_is_not_blocked_yet" check, which is to avoid processing the same cell several times. Whenever a new cell is placed on the grid, repeat the above procedure.

I hope I managed to write this without gross errors (I'm sleepy again). Anyway, it's just a guidance, far from finished code.
Paynterboi TicTacToe
16
Years of Service
User Offline
Joined: 23rd Dec 2007
Location: That one place
Posted: 2nd Oct 2009 07:28
I use the x y coords because the distance formula provides an easy way to make sure that no cells are cliked outside of the range ( without graphics) I.E. if the clicked cells distance from all other clicked cells is less than 3 than it is a legitimate place, I could easily code that into the game the only issue is creating a way to graphically show which cells become un usable. The method i chose for this is to test the distance between the clicked cell and the test cell across the y axis and than across the x axis. At this point it's not whether or not I can code it, simply that I haven't had the time to do so ( and likewise when I do get the time I choose to spend it with my GF or relaxing. Also I have put some effort into creating a calculator that incorporates formula's and methods i'm learning in class to simplify my work, The instructor has permitted the use of the program on tests and such because it is the equivilent of a calculator with the exception that mine provides more uses specific to the class and that mine is free, I have also made my work available to any other students who can use it and gave it to the instructor to upload on his site so that his future students have access to it. )

I post mostly right before I go to sleep just like you which is why I make a large amount of gramatical errors.

EYE R T3H +ick +ack +oe mester
Paynterboi TicTacToe
16
Years of Service
User Offline
Joined: 23rd Dec 2007
Location: That one place
Posted: 4th Oct 2009 02:45 Edited at: 6th Oct 2009 08:15
I told myself, OK!! YOU WILL MAKE A VERSION OF THE GAME THAT, ALTHOUGH IT WILL NOT VISUALLY SHOW IT, WILL ALLOS USERS TO PLACE PIECES ON THE GRID AND PREVENT THEM FROM PLAYING IN RESTRICTED CELLS..

Than I realized I hadn't incorporated a way to determine which part of the arrow I should access when a sprite is clicked. I was thinking the original method, boxindex = clicked - 1; until I realized that the array is multi dimensional. I could change it to a single dimensional array but I would end up needing to recode quite a bit of the game for that. So until I figure out how to determine which sprite to change ( maybe useing dbSpirteCollision() ) I can't upload a working version.

On a brighter note, I dont remember if I mentioned that I incorporated a very easy AI into the original tic tac toe ( simply picks a random square, basically a guarenteed win ).

[EDIT] The for loop provided for placeing the sprites on the screen numbered the sprites differently than expected. The numbers start at 10 and increase by one going down the screen instead of across like I was expecting which caused the code I created to run the game to not work proporly. This isnt a huge proplem it's just not what I expected and my game keeps crashing because of the way I coded it. I use alot of referenses to the spriteid's to help determine where in the array I need to index.

This discovery did however, help out because I went back to make the changes and being the lazy man I am found a spot to replace some code with loops and make my code, at least slightly, easier to maintain.

[EDIT][EDIT] I should have paid more attention to the loop you provided - Codeing lesson 43: PAY ATTENTION TO WHAT YOU COPY AND PASTE ( or dont copy and paste somone else's work without understanding it either way..)

[EDITx3] Ok, I tried to figure out what is causeing the game to collapse but I cannot. I am almost positive that I am attempting to access the array boxs[][] incorrectly but I cant figure out where it is. The source is attached, it compiles fine but when you click a box the game won't work anymore.

I looked up assembly terms to see what

means but it doesn't make sense why it doesn't work, I can only understand that it has something to do with the value of a floating point decimal at 00B8109f in memory ( from what I learned the [eax+ecx*8+0BD5AB0h] is simply 00B8109F expressed in assembly? )

[EDIT] AHA!! ( I think ) the error is within the distance from function, I just realized how horribly incorrectly written it is, it was never updated from the testing stages..

[EDIT] Ok that error fixed, new errors,
= fixed

The playerId Doesn't seem to change proporly anymore..

Also, the valuse in boxsD[][][] need to be changed..

restricted cells are not being restricted.

Ok, I've figured out the issue so i'm going to post it before i get off for the night in hopes somone will have a chance to answer.

Here is the code implimented to place the pieces



The issue as far as the playerId is concerned is that the playerId is evaluated EVERY time the loop to heck the distance runs, meaning that it will change the playerId several times per click ( depending on how many squares have already been clicked )

As far as the distance from function, I believe it doesnt work because if the distance from the FIRST tested cell is < 3 than the square is assigned a player's peice even if the next one to be tested is > 3.

EYE R T3H +ick +ack +oe mester
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 4th Oct 2009 14:42 Edited at: 4th Oct 2009 15:11
I think you are overcomplicating this program a bit. If you look through my previous post once again, I basically gave you the whole framework, including distance calculation and determining array indexes from clicked positions on the screen. Although I said that it's "nowhere near finished code", in fact not so much is missing from it.

I still believe that square root calculation is not needed (unless I misunderstood the rules, but the pictures in the graphical explanation leave little doubt). That gives you a circle, not a rectangle. If the rule requires a distance in "either X or Y direction", where X and Y can be regarded as two sides of a triangle, it is not the same as calculating the third side of the triangle with the Thales rule and checking that distance, if you see what I mean.

I further state that you don't need three-dimensional arrays. I don't know why you pre-calculate and store some coordinates (or distances?) into this array when (1.) distances are easy to calculate on the fly and (2.) the cell which you test is always changing so there is little use for pre-calculated values. The only thing you really need to store about individual cells is one value which indicates if the cell is free, occupied by one or the other player, or blocked. This can be done with a two-dimensional array.

But, as we say in my mother language, "if you listen to me, you do what you want". Every programmer has his own way of thinking.

Regarding your question how to determine array indexes: in the previous post I showed a method with mouse coordinates, but if you want sprite collision, then there is a general method to get two-dimensional data (array indexes) from one-dimensional data (sprite index). Deduct the first sprite index to make the numbers start from zero, then divide that by the number of cells in a row. The result of the integer division gives the row index, the remainder (modulus) of the same division gives the column (both indexes start from zero):



If the array is constructed the other way around, you may need to use number of cells in one column as a divider, or probably the easiest is to reverse the i/j in the sprite display loop. Sorry if my different posts contained different ordering, it's easy to mix but fortunately easy to fix too, and once you understand the principle, it's only a matter of consistent usage.

With this calculation, there is no need to write "if the sprite index is between this-and-this, then it is the first row, if this-and-this, then second row..." Generally you want to avoid hardcoded numbers in a program as much as possible.

One more thing:



In the previous program version you had a similar remark in the "DistanceFrom" function, now you moved it here but it's still a bug. The compiler gives you a warning for using uninitialized variables. There is a long if/else structure here, checking distances from cr and cc, but these variables do not receive a meaningful value. They should probably be arguments of the function, not local variables.
Paynterboi TicTacToe
16
Years of Service
User Offline
Joined: 23rd Dec 2007
Location: That one place
Posted: 5th Oct 2009 23:45
Most of the code above was written before your previous post i was just makeing minor edits as I was posting that I will look at your code once more .

Quote: "I still believe that square root calculation is not needed (unless I misunderstood the rules, but the pictures in the graphical explanation leave little doubt). That gives you a circle, not a rectangle."


True, it does give a circle, but the circle works well with what I was doing.

Quote: "In the previous program version you had a similar remark in the "DistanceFrom" function, now you moved it here but it's still a bug. The compiler gives you a warning for using uninitialized variables. There is a long if/else structure here, checking distances from cr and cc, but these variables do not receive a meaningful value. They should probably be arguments of the function, not local variables. "


I wrote those two functions down with those variables included so that I could understand what I was trying to say when I needed to make the changes to them. If you look at the new distance they were removed and I recoded it so that it would receive the values as parameters ( as you suggested ) and retrun the distance.

[note]I only posted these as responses to what you said, I will make another post after I look through your code again.

EYE R T3H +ick +ack +oe mester
Paynterboi TicTacToe
16
Years of Service
User Offline
Joined: 23rd Dec 2007
Location: That one place
Posted: 6th Oct 2009 01:04 Edited at: 6th Oct 2009 08:13
according to:
http://www.cplusplus.com/reference/clibrary/cstdlib/abs/
abs(n) returns the absoulute value of n and this function is #included from stdlib.h correct?

Am I correct that MaxRows is unnecissary if I Automatically place the inital x?

Quote: "int DiffR = abs(ClickedR - CenterR);
int DiffC = abs(ClickedC - CenterC);

if ( DiffR >= MaxDistR || DiffC >= MaxDistC ) {
// new farthest cell found
MaxDistR = DiffR;
MaxDistC = DiffC;

for (int IndexR = 0; IndexR < MaxRows; IndexR++) {
for (int IndexC = 0; IndexC < MaxColumns; IndexC++) {
if ( this_cell_is_not_blocked_yet ) {
if ( abs(IndexR - ClickedR) > 2 || abs(IndexC - ClickedC) > 2 ) {
// Cell is blocked!
}
}
}
}
}"


Your variable names confused me in this and I was saying WTF over and over and couldn't understand it.

Quote: "How you indicate that the cell is blocked is up to you. In addition to displaying a sprite at the corresponding position (which is easy to calculate from the row/column and the sprite size), you might want to set a flag in the box array as well, which can be useful later if you need to check the status of the cell."

I had originally conteplated useing a 4 in the boxs[][] array as a flag for blocked cells but I was unable to determine a way to block the cells.

Quote: "int RowIndex = (ClickedSpriteIndex - FirstSpriteIndex) / NumberOfCellsInRow;
int ColumnIndex = (ClickedSpriteIndex - FirstSpriteIndex) % NumberOfCellsInRow;
"


I did the math mentaly and if i clicked the sprite with id 11 ( row 2 column 1 ) wouldnt the math for the rows return a 0? If so I would be indexing my array at 0 when I need to index at a 1. ( because 1/5 = .2 and being an int division .2 would get thrown out and 0 will remain ) The column math if clicked on sprite 11 % 5 will return a 1 and index the second column or am I wrong? I believe switching the maths around would be sufficient, I think you made the same mistake with how the sprites are numbered by your loop that I did.

I altered my code to:



This is almost perfect except I think that it will block cells based on which cell is clicked ( clicking a blocked cell will block any un-blocked cells more than 2 cells away ). I believe I can fix this by altering the check at the end of blockedcell() to perform the check before testing distances.

[EDIT] Made the alterations and it appears to work adequately, I just need to add some code to incorporate a visual blockage and I will upload the first functional version of the 5x5. Sorry for takeing so long to complete it, Lots of RL stuff but I try.

What I learned:

Emphasis on use of maths - specificaly to index arrays.
what abs(n) is
Read every post before I post issues

EYE R T3H +ick +ack +oe mester
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 6th Oct 2009 21:35 Edited at: 6th Oct 2009 23:37
Quote: "abs(n) returns the absoulute value of n and this function is #included from stdlib.h correct?"


Correct, it returns the absolute value, but for me it works without including any additional library. To tell the truth, I haven't checked where it comes from.

Quote: "Am I correct that MaxRows is unnecissary if I Automatically place the inital x?"


If the initial X is always in the middle of the 5x5 grid, then there is no need to check the grid after placing the initial X. However, the check that you quoted above occurs after placing the next pieces, so that will still be necessary.

Quote: "Your variable names confused me in this"


I'm sorry about that. Looking through the post, I think the only variables which were not really explained are the MaxRows and MaxColumns, which are the number of rows and columns in the grid and they can both be replaced with 5. I tend to use "speaking names" instead of values, for example in the next post I used ClickedSpriteIndex, NumberOfCellsInRow (which is also 5), etc. which are not really existing variables but I thought the names say what they are. In this respect it's more like pseudo-code.

Quote: "I think you made the same mistake with how the sprites are numbered by your loop that I did."


The main mistake I made is that the sprite display loop is messed up, it displays the sprites arranged from top to bottom instead of from left to right. The best thing would be to correct the display loop, just by exchanging i/j in the line which puts out the sprite:



Then it will be in left-right order which is more logical, and everything else should fit.

If the display loop remains as it is (top-down), then it should be enough to switch the indexes, so what you calculate as row index will be column index. For example, the calculation for sprite 11 indeed returns (0,1) but it should be (1,0) in top-down view.

I think it's time for me to make a few tests as well, just to see in practice that the solutions I'm recommending to you are really workable. I know they should work, but I don't want to be ashamed if some glitch shows up that I haven't thought about, and you've made me interested enough in this game to try to "prove the concept".

**EDIT, a few hours later: so, I did the testing and the concept is workable. Only one small problem came up: if I use the mouse coordinates to determine array indexes after a click, then clicking to the left and above the grid must be separately tested, because the validity check does not work well with small negative numbers. (This does not apply with the sprite collision method.) And of course, numbering the sprites when there are several X and O pictures to display is a challenge, so I got it only half-working, but the framework seems to be good.

A belated reaction to an earlier post:

Quote: "True, it does give a circle, but the circle works well with what I was doing."


It's possible that I haven't fully grasped the purpose of the function. Use whatever works for you. It's rare when two people come up with the same way of approaching a problem. I described how I would do it but it's your decision if that is acceptable for you.
Paynterboi TicTacToe
16
Years of Service
User Offline
Joined: 23rd Dec 2007
Location: That one place
Posted: 7th Oct 2009 02:24 Edited at: 7th Oct 2009 06:24
@Mireben
Your method works, If you read my previous post I stated that I got it working 100% without flaw thanks to you. The only alteration I made that you didn't cover was adding in:



to change the image of all blocked cells. Now it is simply a black Cell but because I have finished the functional portion of the game I will work on updates to the graphics. I'm not sure if I am going to animate the x's and o's because in the previous game it required creating many of the same sprites as opposed to simply changeing the image of them however, Just as in the previous example I can create, use, and delete the sprites just as simply. If you refer to the original post after I finish this I am going to put the most up to date versions of both variations of tic tac toe.

[EDIT] I have begun working with code to attempt to create the Rubix Cube version of TicTacToe.

My Current Issue is that I can't figure out how to assign 27 different Id numbers in this loop:


This is the best one I came up with so far:
(x+z*4)*(y+x)*(z)

Using that to determine the Id of the Object gives 27 different ID's which are:



But I would prefer to figure out something that produces less rediculous numbers.

EYE R T3H +ick +ack +oe mester
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 7th Oct 2009 22:27 Edited at: 7th Oct 2009 22:30
I'm happy that you got the game working! Congratulations! I'll try out the latest version.

ID numbers: This formula should give continuous numbers from 1 to 27. The logic is that the z loop runs 3 times for each iteration of y, and y runs 3 times for each x.



Or, another way is to define a variable which you increment by one in the innermost loop.
Paynterboi TicTacToe
16
Years of Service
User Offline
Joined: 23rd Dec 2007
Location: That one place
Posted: 8th Oct 2009 01:30 Edited at: 8th Oct 2009 01:38
Thanks, I had thought about incrimenting an additional variable but I though there would be an easier method, My calc teach couldn't even come up with a method lol thanks again.

I ran through the Basic3D header file to see what kind of things I can do in 3D. Before I begin to code in 3d could Somone define the following, discribe their usage, and possibly give examples?

Vectors
Shaders
Meshs
Limbs

And Is it possible to group objects? If so, Can I move / rotate them as a group and than ungroup / regroup with different objects?
(think rubix cube)

EYE R T3H +ick +ack +oe mester
Mista Wilson
16
Years of Service
User Offline
Joined: 27th Aug 2008
Location: Brisbane, Australia
Posted: 8th Oct 2009 04:09 Edited at: 8th Oct 2009 04:11
Vectors are containers for floating point numbers. Depending on the vector type. a Vector3 will have 3 floating point values that it contains, a Vector2 will have 2 and a Vector4 will have 4 float values.

GDK vectors/matrices are basically a slower equiv of D3DXVECTOR2,3,4 and D3DXMATRIX objects.

Shaders are something that you will have to spend some time learning about. They are small programs that are designed to affect vertices and pixels, and take alot of the graphics work away from the CPU and put it where it belongs on the GPU. There are some great info threads in the DarkBasic forums about Shaders and how to write them, also look for posts by a user named "Green Gandalf", he is our resident shader expert, and will help you as much as he can.

Limbs are kind of like "Objects contained in an object". A way of thinking of them is in a similar manner to DirectX Mesh Subsets. You can have multiple limbs that are not connected at all, like a solar system for example, but all one object.

Using the solar system example, the "original" object could be the sun. Then each of the other planets, could be added as a limb and positioned, rotated, scaled etc. One advantage is that you can just apply scaling or translation or whatever to the object, and all of its limbs will share the procedure. A Disadvantage is culling. GDK will not cull limbed objects at all without you manually creating the code to do it. What this means is the if even 1 poly of a limb is inside the frustrum DarkGDK will render the entire object, even if NONE of it bar that single poly is visible it still all gets rendered, which can be a large bottleneck if not handled correctly.


Meshes are kind of what objects are made out of. You can make meshes from objects or limbs or memblocks(though thats more complex again), and then alter the mesh with GDK commands to add or remove verts, to translate or scale verts or whatever, then you can create a new object or limb from the mesh, incororating the changes that were made to it.

I wont go into actual examples of usage as you can find many many usage examples for all of the above by spending some time searching, and I have rattled on enough I think lol

Oh and before I forget, to answer you question, Yes, it is possible to "group" objects etc... using limbs would be one way, a static universe could be another, or you could just code your own methods for creating a "group" of objects, possibly using an STL container type(a std::list, or a std::vector) to keep track of which grp contains which objects etc(maybe a std::map would work better, though you would need to have a think about how you wanted to code it).

If it ain't broke.... DONT FIX IT !!!

Login to post a reply

Server time is: 2024-10-01 20:22:27
Your offset time is: 2024-10-01 20:22:27