Sub's coding pool party

Cunning as Zeus
Banned
✔️ HL Verified
💻 Oldtimer
Joined
Nov 23, 2003
Messages
6,079
Best answers
0
He'll make an Insignificant Nations expansion later on.
 

sub

Active Member
💻 Oldtimer
Joined
Jun 18, 2003
Messages
5,961
Best answers
0
That would mean that the first release would only feature AMERICA
 

sub

Active Member
💻 Oldtimer
Joined
Jun 18, 2003
Messages
5,961
Best answers
0
So mechanically the game is done with the exception of one thing. When you attack a country or move your armies, I want the player to have a choice of how many armies to attack with or how many armies to move from one territory to another. Right now it's an all or nothing thing, because I'm not sure how to convey the choice to the player. A lot of risk games have a pop up asking you this, but I think pop up's are pretty terrible and I want to avoid doing that. Right now it looks like this



So the player is green, Ukraine is selected and that grey territory next to Ukraine is selected to attack. If the player wants to attack, he can press the button or he can simply right click anywhere on the map. I was thinking I could perhaps do something like have radio buttons on the bottom for a few choices



But I don't like the fact that they're on the left side and the attack button / end turn button are on the right. If I grouped them with the attack button, then the "alternatively you can press right click to attack" would be a bit out of place. I don't know

After that I just need to start coding the AI, which for me should be impossible, but I'll give it a shot.

--- edit ---

I guess I'm going to go with a drop down box.



For every 1 troop moved/attacking, the number on the right would represent how many are left behind.
 
Last edited:

sub

Active Member
💻 Oldtimer
Joined
Jun 18, 2003
Messages
5,961
Best answers
0
So this Risk thing is going pretty well still. Functionality wise it's done, I just need to add AI and multiplayer if all goes well.

I started work on the AI tonight. Right now the AI will decide on a continent to pursue capturing (based on things like # of its own troops already in continent and # of enemy troops in continent; eventually will take into account how many chokepoints the continent has, how many additional troops it'll gain if the entire continent is captured, how close the continent is to the mass of its forces/any continent it already has captured, and anything else I can think of that I think will make a difference) and it'll focus on assigning troops in that continent. It will try to do at least one attack per turn, since if you capture a territory during a turn you'll get a card, and you can hand in cards for bonus troops at the start of turns. If it thinks it can conquer a territory in a continent that it's trying to capture, it'll attack. I think I'm going to have some of the AI play different from each other, so one might be more aggressive, one might spread its forces out more where as another might keep its armies clumped up in one or two territories.

The AI has only got a few hours of work right now, but I'm hoping to make it at least semi decent. Also added a continent view mode, so you can see where the continents are and how many additional troops you'll gain if you hold every territory in that continent.

 
Last edited:
Force Pit Member
Joined
Dec 1, 2002
Messages
874
Best answers
0
Sounds cool Sub! Is it possible to get the AI to play agains each other when you have set everything up with different types of AIs? It would be cool to do some testing and to see who wins more often and what patterns are used when playing together. From that I think you can add/tweak to the AI to make the win ratio a lot more balanced between the different AIs. :)
 

sub

Active Member
💻 Oldtimer
Joined
Jun 18, 2003
Messages
5,961
Best answers
0
Thanks man.

So when you're starting up a game, you can choose how many AI's there are, you can even choose to have an AI fill your spot. I'm not sure how much control there's going to be for the AI's, I guess I could try to make the AI's behavior modifiable from there too. I was actually thinking of doing what I did with the Tetris AI for this, have the AI learn how to play by playing itself.
 

sub

Active Member
💻 Oldtimer
Joined
Jun 18, 2003
Messages
5,961
Best answers
0
The AI is dumb as rocks right now, but I managed to lose


 
Last edited:

sub

Active Member
💻 Oldtimer
Joined
Jun 18, 2003
Messages
5,961
Best answers
0
I'm going to try to finish up what needs to be finished today. I added in saving/loading last night, and just added in some graphs and stuff a little while ago.

http://i.imgur.com/o6WJMbr.png

The map in the background is terrible map, but I only made it for testing. But basically, I have to fix a bug with the AI assigning double the amount of units they should be when they hand in cards, I need to verify that the stats are working correctly (it keeps track of how many games you've played, won, lost, total number of turns played, and possibly something else), and maybe try to make the AI a bit better.
 
Just a nice person :)
✔️ HL Verified
Joined
Jul 17, 2009
Messages
262
Best answers
0
That graph is sweet! You made it all yourself?
Looks like it's getting close to 100% playable?

Of course, a game is only done when you say it is and it probably needs
many little things. Still. Awesome job Sub.
 

sub

Active Member
💻 Oldtimer
Joined
Jun 18, 2003
Messages
5,961
Best answers
0
Nah, I didn't make that. It's a library written in c# called ZedGraph, http://sourceforge.net/projects/zedgraph/.

I'm not entirely sure how to handle the pathfinding for this. I get that I can use a*, but let's say that an AI has a collection of territories that it wants to use to conquer a continent. How do you get them to execute that attack in a way that makes sense, so maximizing the number of territories conquered while also allowing the armies to end up in locations that make sense (ie, either on a continental chokepoint or a territory that has at least one enemy territory next to it)? Do I just have to brute force it?
 
New Member
Joined
Nov 24, 2001
Messages
692
Best answers
0
http://en.wikipedia.org/wiki/Graph_theory
At first glance your problem doesn't seem to be a 'standard' one though. You could just brute force it, assuming that you can attack about 4 territories from each territory, you can calculate 10 attacks deep by evaluating 4^10 = 1048576 positions and pick the path you like most out of that. Or you could start at a sensible point and work your way back from there to a point you have armies at.
 

sub

Active Member
💻 Oldtimer
Joined
Jun 18, 2003
Messages
5,961
Best answers
0
Thanks Harsens, as usual you are the man. I ended up doing a combination of starting at a sensible point and working my way backwards, brute forcing the evaluation.

The project is at a point where I'm happy enough with it to move on for now. It could use more work, but so could everything, and I think it's a decent clone of Risk.

I read something the other day that motivated me to start work on another project, which I'm thinking of calling "A Spaceship Odyssey" at the moment. I'll let you guys guess what it could possibly be about.
 

sub

Active Member
💻 Oldtimer
Joined
Jun 18, 2003
Messages
5,961
Best answers
0
Close. It's about turtles.
 
New Member
Joined
Nov 24, 2001
Messages
692
Best answers
0
Thanks Harsens, as usual you are the man. I ended up doing a combination of starting at a sensible point and working my way backwards, brute forcing the evaluation.

The project is at a point where I'm happy enough with it to move on for now. It could use more work, but so could everything, and I think it's a decent clone of Risk.

I read something the other day that motivated me to start work on another project, which I'm thinking of calling "A Spaceship Odyssey" at the moment. I'll let you guys guess what it could possibly be about.
No problem, those are interesting problems to spend a bit of time pondering on. Nice to see you pick up my half-thoughts and build something useful out of them :)

I have been planning to type something on your "knowing how to structure a project that's more long term" question, but haven't really had the time to come up with anything profound on that. This is something all programmers struggle with though (if they say they're not I'd say they're either lying or extremely incompetent). You seem to have at least developed a gut feeling on what structures are ugly, so that already helps you get better at that.
 

sub

Active Member
💻 Oldtimer
Joined
Jun 18, 2003
Messages
5,961
Best answers
0
Yeah, that would be awesome. Knowing how to structure your code is definitely one of the hardest things about programming, especially if you're working by yourself and you don't get much feedback from others.

In other news, I went and remade Conway's Game of Life because I'm an idiot. I feel like the first clone I made was really good, but the code was pretty terrible, and it bothered me that it was limited to 160 x 100 cells on the grid, and to go with that it bothered me that you couldn't resize the window.

So I spent the past three days remaking it, it now features an infinite grid, resizable window, zooming in and out, and all that fun stuff. I'm sure it's better performance wise, too. I don't think I'm going to release it, but it was a cool little weekend project.

The infinite grid is really just a series of connected 800x600 grids which appear dynamically depending on where they're needed. So it starts off with one grid, and if you click in an area where no grid exists, a new one will pop into the appropriate position. Grids will also appear if you have an alive cell on the edge of one of your grids. The memory gets freed up when a grid is no longer needed. I'm pretty happy, accomplished what I set out to do.







Also spending a lot of time looking into engines and frameworks... I don't think I want to use Unity, but it seems to be the best option out there.

edit: Also, SDL2 was released today. Going to check that out too.
 
Last edited:
New Member
Joined
Nov 24, 2001
Messages
692
Best answers
0
So, a first version of my "knowing how to structure a project that's more long term" post. I guess I'll just throw in a few tips for beginning to intermediate level coders on relatively small solo projects.

1. Learn some (drawing) techniques for design. I tend to use class diagrams, state machines, pseudo code, boxes with arrows I thought up myself, sequence diagrams... In my experience it's not really worth to use custom tools for this, since the design is typically not kept up to date with the code anyways. My typical design is on scrap paper or on a whiteboard (use a cellphone camera to capture these).

2. Spend some time thinking stuff through before you start coding, but don't try to design everything up front. Don't go overboard with the drawing techniques you've learned, only use those that fit the problem you're dealing with. It often works out to first make the minimum thing that works and then redesign a bit to add new features.

3. Find a coding/design buddy. When designing or coding something alone you can get tunnel vision. Designing something together, or discussing your design with someone can help you improve it or get fresh ideas. Coding together can prevent stupid mistakes (that might take hours to fix) and can help you learn new ways to solve problems.

4. Get your code in a version control system, both to have a backup and to be able to go back/look at older versions.

5. Go back to your code every now and then and check if the old design is still nice with all the features you've added on top of it. Cleaning up and redesigning the code might be worth it. If your code feels clunky but you don't know exactly why, it might help to draw some diagrams on it and play around with changing those first rather than directly with the code itself. Redesign and cleanup might however introduce bugs, you can use the version control to check how previous versions worked and where exactly you broke stuff. Some IDEs have special functionality to help you redesign code without changing its functionality (this is called refactoring). I'm not sure how good tool support for this is in C++/visual studio, but if something is available, it's worth getting familiar with it.

6. Copy-paste is evil. Whenever you copy-paste something (and change it a bit) you now have to maintain the same code at least twice. A typical way to avoid copy-pasting is to build a function with the copy pasted code, with the stuff you needed to change as parameters to that function.
 

sub

Active Member
💻 Oldtimer
Joined
Jun 18, 2003
Messages
5,961
Best answers
0
Thanks for the post Harsens. I've started to create visual diagrams which shows how the code would be ideally structured, it really does help a lot. I really do wish I had a coding/ design buddy though. I have a few different people I can ask for help, but there's only so many times you can bother someone with those things before it becomes too much.
 

sub

Active Member
💻 Oldtimer
Joined
Jun 18, 2003
Messages
5,961
Best answers
0
Question for Harsen's or Dutchmeat or anyone who knows what they're doing, really.

Right now I'm not using any global variables or objects, because everything I've read says that they're evil and to be avoided. I have a class called Application which contains the window object, functions which tell you the current screen size, functions which tell whether or not a point is within the screen, and this class also contains another class that's used for drawing primitive shapes / text / I suppose you could draw anything you wanted with it. It just contains some core useful functions.

Don't judge me, but it would be pretty convenient to make it a global variable. Specifically to add in Application.h

extern Application App;

and then before main declare it so it can be used anywhere that includes "Application.h". Would it be super terrible if I do this?
 
Last edited:

Users who are viewing this thread

Top