Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 148 149 [150] 151 152 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 902499 times)

Simmura McCrea

  • Bay Watcher
    • View Profile
    • My Steam profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2235 on: April 19, 2012, 02:30:19 pm »

Code: [Select]
PC.Shoot(Bullets[MAX_BULLETS]);
Logged

Sowelu

  • Bay Watcher
  • I am offishially a penguin.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2236 on: April 19, 2012, 02:33:42 pm »

Code: [Select]
PC.Shoot(Bullets[MAX_BULLETS]);

Oh!  That's simple.  Bullets[MAX_BULLETS] refers to a specific entry in that array.  Bullets is a pointer to the stuff in the array, Bullets[something] isn't an array of size "something" but is instead something inside it.

I believe you want to just do PC_Shoot(Bullets)?  It's been a while but you should be able to make some sense of that at least <3

Or, to be more specific.  "Bullets" is a pointer to a pointer to a bullet.  "Bullets[MAX_BULLETS]" is a pointer to a bullet, and furthermore, it is just past the end of the array.  <3

Pointer shenanigans are the only thing I like about C++.
« Last Edit: April 19, 2012, 02:35:39 pm by Sowelu »
Logged
Some things were made for one thing, for me / that one thing is the sea~
His servers are going to be powered by goat blood and moonlight.
Oh, a biomass/24 hour solar facility. How green!

Simmura McCrea

  • Bay Watcher
    • View Profile
    • My Steam profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2237 on: April 19, 2012, 02:35:36 pm »

Oh, herp a fucking derp. Yeah, was precisely that. I'm an idiot.
Logged

GalenEvil

  • Bay Watcher
    • View Profile
    • Mac-Man Games
Re: if self.isCoder(): post() #Programming Thread
« Reply #2238 on: April 19, 2012, 11:43:22 pm »

Okay, took several days to read through all 150 pages of this thread... omg this thread is awesome! Well, playing around with Visual Studio C++ I made a test project to see what I still remember from my college C Programming Class. I remade my final project for that class, except instead of just having a Player v Player mode it has a Computer v Computer mode as well! This is a great success for me as I was able to, rudimentarily at best, recreate the process that a human player goes through when playing 'Battleship'. This process would be a) pick a random position to attack if there are no likely known locations that an opponent's piece could be located, or b) attack around a hit piece if it would be a good idea to do so.

For a: basically just pick some random position from the map that might have a chance of containing a piece. Obviously positions surrounded by 4 misses, as the ships can only be placed orthogonally, will have no chance of containing a hit and are thus skipped for inclusion. It uses what I call a "success map" that has values associated with hits, misses, and non-attacked positions and assigns them values. According to the most recent move the map is updated and a gradient-shift-y thing is applied to the map... easier to show i think.
Code: [Select]
This is the map as the computer "actually sees" it. Note: the (X) means that no move has been made to that position
X X X X X X X X X X
X X X X X X X X X X
X X X X X X X X X X
X X X X X X X X X X
X X X X X X X X X X
X X X X X X X X X X
X X X X X X X X X X
X X X X X X X X X X
X X X X X X X X X X
X X X X X X X X X X

This is the "success map" that the computer "sees" as well.
4 4 4 4 4 4 4 4 4 4
4 4 4 4 4 4 4 4 4 4
4 4 4 4 4 4 4 4 4 4
4 4 4 4 4 4 4 4 4 4
4 4 4 4 4 4 4 4 4 4
4 4 4 4 4 4 4 4 4 4
4 4 4 4 4 4 4 4 4 4
4 4 4 4 4 4 4 4 4 4
4 4 4 4 4 4 4 4 4 4
4 4 4 4 4 4 4 4 4 4

All of the 4s represent neutral locations and this is the default state of the map

Okay, now that the initial information is added, let's throw in a Hit and a Miss at positions 4,4 and 6,4 respectively. The coordinates are on a 1-10 system for the example

Code: [Select]
X X X X X X X X X X
X X X X X X X X X X
X X X X X X X X X X
X X X H X M X X X X
X X X X X X X X X X
X X X X X X X X X X
X X X X X X X X X X
X X X X X X X X X X
X X X X X X X X X X
X X X X X X X X X X

The above is the map that the computer player and human player can see, below is the success map that only the computer can see while it tries to guess where your ship is

4 4 4 4 4 4 4 4 4 4
4 4 4 4 4 4 4 4 4 4
4 4 4 5 4 3 4 4 4 4
4 4 5 8 4 0 3 4 4 4
4 4 4 5 4 3 4 4 4 4
4 4 4 4 4 4 4 4 4 4
4 4 4 4 4 4 4 4 4 4
4 4 4 4 4 4 4 4 4 4
4 4 4 4 4 4 4 4 4 4
4 4 4 4 4 4 4 4 4 4


It might be a bit hard to see but at position 4,4 where the hit was placed there is now an 8, and at the miss there is now a 0. These are the default values for hits and misses. Surrounding the hit and miss positions orthogonally are the gradient effect that occurs when a hit or miss are recorded. Above, below, and to the left of the Hit the values are increased by 1; above, below, and to the right of the Miss the values are decreased by 1. Between the Hit and the Miss the value is unchanged because the +1 from the Hit and the -1 from the Miss are negated.

Another short example for when a position is surrounded by Misses

Code: [Select]
X M X X X X X X X X                  2 0 3 4 4 4 4 4 4 4
M X X X X X X X X X                  0 2 4 4 4 4 4 4 4 4
X X X X X X X X X X                  3 4 4 4 4 4 4 4 4 4
X X X X X X X X X X                  4 4 4 4 4 4 4 4 4 4
X X X X X X X X X X                  4 4 4 4 4 4 4 4 4 4
X X X X X X X X X X                  4 4 4 4 4 4 3 4 4 4
X X X X X X M X X X                  4 4 4 4 4 2 0 2 4 4
X X X X X M X M X X                  4 4 4 4 3 0 0 0 3 4
X X X X X X M X X X                  4 4 4 4 4 2 0 2 4 4
X X X X X X X X X X                  4 4 4 4 4 4 3 4 4 4

You can see that for the top left of the grid where Miss marks surround a corner, the computer now thinks that this is a very unlikely place to have a ship piece. In the bottom right you can see that the computer has given up any hope of a ship piece being within the 4 Miss marks surrounding it.


Well, not sure if that is explained well but I am on a different computer than the one I made it on so don't have direct access to the code to show ya :P If there is interest I am probably going to give a go at making a GUI for it and just reusing the AI algorithms for it since it seems like it might actually be decently hard to beat. I haven't made a Player v Computer mode for it so should probably get that up and running first to see how good my AI actually is. I am expecting a middling-skill player on the side of newbie though. Two AI against each other gives some pretty even matches, usually it's nearly 50/50 for each player's win/loss percentage over a few hundred games.

GalenEvil
Logged
Fun is Fun......Done is Done... or is that Done is !!FUN!!?
Quote from: Mr Frog
Digging's a lot like surgery, see -- you grab the sharp thing and then drive the sharp end of the sharp thing in as hard as you can and then stuff goes flying and then stuff falls out and then there's a big hole and you're done. I kinda wish there was more screaming, but rocks don't hurt so I guess it can't be helped.

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2239 on: April 19, 2012, 11:57:01 pm »

Sounds awesome.  I say go for it with the GUI.  Assuming you have any experience with GUI programming, this should be pretty easy to do.  And it could be a fun little puzzle.
Logged

GalenEvil

  • Bay Watcher
    • View Profile
    • Mac-Man Games
Re: if self.isCoder(): post() #Programming Thread
« Reply #2240 on: April 20, 2012, 12:44:04 am »

Once I get the program onto my desktop which has SOOOOOOOOOOOOO much more power I am gonna time it then give it a nice 1 hour run and see what kind of numbers I come up with. That should give me enough time to come up with at least a tile-scheme and maybe some drawings to go with my UI. If I can make it a fullscreen app it might be worthwhile, and will look more like retail games. I am hoping to give it animation and some 3D models using Blender + DX9 or DX10 if I think that my userbase would benefit from the upgrade. Basic version will look very similar to the very old and awesome Win3.11 Chess game. Top-Down static images for each piece (side-view of pieces, top-down view of board).

As an added bonus that I coded up as some additional functionality, the AI player will place its ships according to size and usually does a really good job of it. Most of the time it does not need to redo the position map, and if it does it only cycles through maybe 10 maps at the most and that is with a large number of ships. I think that it can do 5 ships of sizes {5, 4, 4, 3, 2, 2} pretty well. It will automatically rotate a ship if it doesn't fit right where it wants in the orientation it wants, and if that won't fit either it will pick a new position ruling out the position(s) taking into account what it knows about the game board. I really wish I had it on this computer... would post the entire thing right here :D

I have a FPS DX9 engine most of the way completed, some level editor stuff needs to be finished but that's about it. If I can get a 3D dynamic cave designer created (eventually, WIP for the past 2 months but that's just pen-and-paper work) I will add that to the level designer and get some cave systems going with that engine heh...that's beside the point of the post tho >.>

Right now the game runs from the DOS-Console with no real commands. Start it from EXE APP and follow prompts until it starts spewing lines at you. It will save all of the games to a file so you can see the start and outcome of each game and at the end of the file it will give you a win/loss record for each player.

I think I spent about a week typing it all up, just happy that it works :D

GalenEvil
Logged
Fun is Fun......Done is Done... or is that Done is !!FUN!!?
Quote from: Mr Frog
Digging's a lot like surgery, see -- you grab the sharp thing and then drive the sharp end of the sharp thing in as hard as you can and then stuff goes flying and then stuff falls out and then there's a big hole and you're done. I kinda wish there was more screaming, but rocks don't hurt so I guess it can't be helped.

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2241 on: April 20, 2012, 01:34:00 am »

Sounds like you're doing well with it.  If you intend to give fullscreen capability, please please please have a window mode option and make that the default.  Personally, I hate running things in fullscreen and having it default to fullscreen kind of annoys me.  Most commercial apps do have a windowed option which sadly isn't often the default.  Also, if you're up to it, considering using SDL.  It'll handle a lot of the hard work regarding video, audio, and user i/o for you.  It's also crossplatform, which would more easily allow compiling for a Mac or Linux target.  And try not to make the required specs too high.  Not all of us have uber-god computers.  Sounds like you're doing a very good job here, though.  Keep it up and above all else, be sure to finish (and ideally put it out).
Logged

GalenEvil

  • Bay Watcher
    • View Profile
    • Mac-Man Games
Re: if self.isCoder(): post() #Programming Thread
« Reply #2242 on: April 20, 2012, 02:33:49 am »

Right now I am not entirely sure how to do fullscreen work in C++... probably not all that hard but I want to get my window GUI down pat before I try to force it to work with whatever native screen resolution a user might have...

I don't plan for it to be really high tech in any case. For my shader I expect to use something whatever standard was around 5-10 years ago that is still supported by current hardware.

I am actually pretty good at altering my code so once I get a basic Windows version going I may end up switching to SDL for compatability. Also, I prefer to learn things the hardest way possible to prove to myself that I can do it, then look for easier ways and optimizations. Point in case, with the newest Elder Scrolls iteration, Skyrim, I made a simple text file of ingredients and effects and java'd my way into making a brute force recursive checker to virtually create every possible combination of ingredients for potions while culling out any that had duplicate entries in different orders. First time I ran through it all the way I made a multi-GB debug file as it went line by line through my code adding pieces, creating potions, and culling them. Took about 6 hours on my machine before my upgrade. After removing the debug code it took about 12-15 seconds to iterate and parse everything out. Debugging makes things sloooooow down so much :( even with batch writes...

But enough of that... I need to learn some basic GUI stuff anyway for C++, since right now I have just been playing a Matrix-y game with my engine and looking at crap scroll down the screen for hours on end. Will be nice to see something colorful and not so jumpy for once :P (imagine a FPS with ascii graphics attempting to be representations of 3D objects, constantly scrolling to work at about 20fps, with just large blocks of crap and sketchy cursor movements using wasd and udlf-arrow keys to look about and you will imagine my horror)

Half of the console-fps visualization engine got lost when I broke my computer so will have to build that back up before I work on my GUI representations with textures and meshes... I am also a complete newbie at Blender so if someone could give a good tutorial on that stuff would be nice... I can do some really basic stuff and make super low-poly textures that should get a supportable 1000 or more on screen at once with DX9 and my laptop (cheapest at wal-mart 179$ USD last Christmas)

Okay, so... my planned functionality inclusions for my battleship game:
*   Windowed mode multiple resolutions (640x480, 1040x800, 1280x1040) or whatever the standard resolutions are at that range i dunno... I work with a rather high resolution display on my LCD screen desktop
*   Will try to make it compatible with XP, will have to have an XP tester though since I do not have any computers w/ that OS on it
*   Really basic graphics, not even worthy of using DX on other than as a placeholder for more advance models when I get the chance for the next version
*   a UI with mouse-click interface and options screen for even lower quality graphics (for super old computers)
*   The Default graphics quality will be set on startup the first time, so might take a little while for it to start up the first time... after that should start up quickly :D
*   Possibly adding in moddability with a shipImages folder where the user can change pictures out for better/different ones of the same name, or a Mods folder where the user can pick a shipMod to use and that will replace the existing ship pics

I think that is all, I can probably write more details if anyone would like. Thanks for the support of the project Stargrasper! I was honestly unsure of whether or not to proceed with the project since it has been sitting in my completion folder for the past few months.

I have everything that I work on for programming in a giant folder next to my bed for in case I start thinking of something cool. Thought of an EVE Clone that would actually play very similar to the X series by Egosoft but with some minor online interaction a la EVE w/ all things created from bottom to top at manufacturing centers... but that is a lofty goal for now and not something I can complete within even a year of hard work so putting it aside to boil and reduce to something manageable :D So many ideas, most of them are utility programs for games like Oblivion, Skyrim, Railroad Tycoon 3, and SimCity 4 Deluxe Edition. That may be because I am an engineer at heart, and am really good at figuring out how things work and remaking them (essentially reverse engineering).

Okay, I think that's enough for now, will take a break and let someone else spew thoughts from their fingertips :D

GalenEvil
Logged
Fun is Fun......Done is Done... or is that Done is !!FUN!!?
Quote from: Mr Frog
Digging's a lot like surgery, see -- you grab the sharp thing and then drive the sharp end of the sharp thing in as hard as you can and then stuff goes flying and then stuff falls out and then there's a big hole and you're done. I kinda wish there was more screaming, but rocks don't hurt so I guess it can't be helped.

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2243 on: April 20, 2012, 07:36:40 am »

Battleships, huh? You'll be interested in this then.
Logged

armeggedonCounselor

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2244 on: April 20, 2012, 11:48:24 am »

I've got another wonderful problem.

Spoiler (click to show/hide)

I'm trying to get a list of names out of a file with a couple different data types. Here's the input file:
Spoiler (click to show/hide)

What the current iteration does is take the entire line and put it in as Names[row]. Clearly this will not work.
Logged
Quote from: Stargrasper
It's an incredibly useful technique that will crash the computer if you aren't careful with it.
That really describes any programming.

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2245 on: April 20, 2012, 12:57:14 pm »

Code: [Select]
studentdata >> name >> int1>>int2>>int3>>int4;
Or something like that.
Streams ftw.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #2246 on: April 20, 2012, 02:30:49 pm »

I don't think you can overload file input... can you?


Anyways, thanks for showing that to me - getline(). Now I can do what I wanted to do! :D
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #2247 on: April 20, 2012, 02:36:04 pm »

I don't think you can overload file input... can you?


Anyways, thanks for showing that to me - getline(). Now I can do what I wanted to do! :D

You very much can overload the stream in and out operators in c++.
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #2248 on: April 20, 2012, 02:42:16 pm »

Weird, every time I tried that I got complaints from the compiler xD Must have been some other error T_T

Anyways, just for the record, I'm making a simple genetic drift simulator. I hope I carry it out to the conclusion.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #2249 on: April 20, 2012, 02:59:10 pm »

Weird, every time I tried that I got complaints from the compiler xD Must have been some other error T_T

Anyways, just for the record, I'm making a simple genetic drift simulator. I hope I carry it out to the conclusion.
example:
http://www.java2s.com/Code/Cpp/Overload/Overloadstreamoperator.htm
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.
Pages: 1 ... 148 149 [150] 151 152 ... 796