Tuesday, January 24, 2017

OODA Loop Strat

Deciding To Use A Decision Cycle

I recommend looking into the military strategy called Observe-Orient-Decide-Act or OODA for short. Here is the Wikipedia page about it. Basically it is a really good concept to implement and a nice frame of mind to have. It will help you keep your actions focused and overall your bot more effective.

The Gist Of It

Instead of blindly hacking away at your spaghetti code, filling in the gaps as you go when you think of more/better strategies, try this. No matter what you are coding keep it within the OODA loop. Always make sure your logic follows these four steps and in this order.

1) Observe

Each time a unit takes its turn have him preform his actions by first pulling together any available information. This can be from the broadcast channels as well as from sensing nearby objects/dangers/resources.

2) Orient

This is where you want to try and use some prior knowledge to make an inference as to what you believe is going on. Are you pinned down and can't move? Are you under heavy attack? Are you about to die?

How can you apply the knowledge you have not only of your state but the state of the entire map or the entire match for that matter? Using what you have known and what you now know, do your best to figure out what is going on.

3) Decide

Now that you have properly assessed your surroundings and yourself, it's time to choose what to do. Your units can be built to do tasks very well. You can even delegate tasks to have units, even of the same type, doing different tasks for you. This is great, but by following an OODA loop for each unit you can now use those same strengths more effectively.

Instead of hard-coding tasks and blindly delegating to units, you are now in the mindset of dynamically assigning goals/tasks based on actual game play. Once you are able to accomplish this concept, you will see it's a game changer.

4) Act

There's nothing to it but to do it. By this point you have done your homework and decided if your unit needs to use this turn to focus on aggression, evasion, exploration or development. Make it hap'n capt'n, and quickly before you run out of bytecode.

Rinse And Repeat

Keep following this circle of logic to guide your decisions. Each unit on each of its turns should in some way step through this logic loop.

Link Me Up Scotty

Since I haven't been very on top of Battlecode lately, I figured I would share some other resources I've found, in no particular order, in case you were looking for something related to Battlecode to dig into. I'll try to add more as I come across them.

Sunday, January 22, 2017

Off The Grid

Away From Keyboard

I've been a little AFK lately. Not dead, but not far off, lol. I'll also be on the road a lot this week and among other things I have to handle a lot of serious adulting type stuff this week but hopefully I'll get back into Battlecode. Honestly I haven't even touched anything since the new post-sprint changes were posted. With all the serious stuff I need to accomplish this week, maybe Battlecode will be the perfect distraction to keep me balanced.

Thursday, January 19, 2017

Sprint Tournament Is Over

Good Game

Well, played. Now take the night off and relax. Hit it hard again tomorrow but be ready for some major changes to be released by the devs which they say will make you have to rethink your strategy.

Basic Bot Mechanics

At this point you have your basic bot mechanics working. You are building units and fighting. They are searching and shaking.

Now Start Baking With Those Ingredients

Think of what you have so far as walking up to the buffet and seeing all the individual ingredients sitting out there to choose from. Ok, if you are starving and just need to survive that'll work, but let's do better than that. It's time to keep refining those ingredients to make them better but also to start using them to make better stuff. Time to make groups of logic work together so you end up with a buffet that you'll want to eat at.




Wednesday, January 18, 2017

Pre-Populating Units for Micro Debugging

Totally Deprecated Concept To Follow

I was just about to start coding this last week when I got really sick and then couldn't do anything. I literally spent a few days in a row focusing on each breath with my heart racing the whole time and now I am in the hospital.

I had already typed up this description of it and had planned to get it working well so I could share the code freely with everyone that wanted it. Now it is all useless, thankfully, because the super awesome devs added the feature to the map editor (actually, there might still be some useful thoughts on initializing units if you can figure that out somehow).

The Old Idea - Refactored To "Don't Read Me"

There were no options yet on the map editor. So to hack it together without having to build your own map editor the following is what I was building. Oh and no, not the cool l33t kind of hacking but the sloppy hack it together or being a hack at something sense of the term.

Before Switching To A Robot Type And Looping Forever

Set up a map building routine that says, if I am Team A, I am going to build these troops and place them at these locations and then tell them to wait (aka auto yield) until I note that all troops are ready for the match to begin.

The same routine can have a check for if it is Team B and have its own list of troops/locations/inits. When you know everything will have had a chance to build you can start the game.

Call this routine from your main RobotPlayer.java class and hop out of it and on to your normal stuff as soon as everything is built/initialized. Use the broadcast array to organize a bit and flush the array back to zeros when done.

The Limitations

There are a few over-sites with this, it won't play out exactly as your bot normally would because normally they would have had time to do things, learn stuff and be hurt by the time they got to that position, but it will still work out nicely for testing your micro fights within the map. Also you loose overall rounds that are possible, so however long you took to setup that map will cut from overall play time but in most cases when doing this you are really more interested in micro fights and testing how they play out anyway, so it works.

Unlimited Bytecode

This will never be used in your final bot for actual fights, so you can drop all of this code in debugging functions and not have to worry about any bytecode limits as you are setting up the map.

Storing Units And Location List

I was making two multidimensional arrays. One that Team A would chew through and one for Team B. This way you could have the same RobotPlayer.java play both sides if you wanted. Technically it could be done with one multidimensional array and an extra spot to denote the team, but I like the clarity of splitting it out so later on copy and pasting preset spawn groups is easier and especially easier if you plan to use inits described later on here.

The array would hold types needed and a sub array for location or location paths. The location could in that way be a list of x/y points to make way points or just one final x/y point to go to. Doing that skips any pathing code because we know the maps we will be using this for. If it is a clear walk from spawn to their starting position they only need that one location. In the case you need it to move around trees or other spawned bots you can give a locations in order for it to step through on the way there. Thus, no pathing headaches.

The last piece of data I would denote in the arrays for each bot is a switch case integer. This is optional and could be used to overcome the limitations listed above. Actually, I'd have to get pretty creative but this could probably still be used in conjunction with the new map editor that let's you place units.

Taking It Up A Notch

Then I was going to make it possible to follow up with some optional code to initialize some or all of the bots. Meaning once all bots were in place I would step through the arrays and look at the switch case integer if given.

Using that I would switch to different sections of initialing code. That could be crudely written, copied chucks of code or specific function calls to get trees built around it or to inject some information that it needs and should have learned on its own by this point. These calls could do some things this bot needs to have already done so that I can properly test a micro fight.

Dropping The Starting Flag And Flushing

I would probably use the broadcasting array as a way of organizing the bots for each team. So I would grab the first set of spots and claim them for things like map information, number of each unit type needed and whatnot. Of course not having to worry about any kind of conservation, knowing I will flush the broadcast before staring the match.

After those channels I would have a set representing the array index positions for the team, no matter if it is A or B here because they won't be seeing each other's channels so they won't overlap. The first bot listed for either team in the array would be at broadcast channel number 0 + OFFSET the second 1 + OFFSET and so on; where the offset is however many channels I used up for the beginning block of information mentioned above.

Each time a bot is built it can be enlisted to one of those spots in the broadcast array by raising the flag at that position if it was the first bot of the correct type to see it was still needed. It can also decrement the channel integer corresponding to the number of that type of units needed to be enlisted still.

Process Summary

The basic overview of that process would be to build bots still needed, enlist them by claiming a spot in the broadcast, move them to position, and set the broadcast integer to denote that it is in the starting position and ready to init. Continuing to make any bot initialization as needed, if started before all positions are taken, trees can help save rounds here. Finally once all bots are made, in place and initialized we will raise the starting flag so to speak and flush the broadcast array back to all zeros.

Getting Teams To Talk To Each Other

The only (ok, another) wonky part to this is that you will need both teams to start at the same time still, both teams that can't see each other. To do this you'll need to run it once to see how many rounds each team takes to finish the setup process. Whichever one takes longer you will need to hard code into the function as your starting round (the round after that actually).

Stop Staring At Me Swan

No seriously, lol, why are you still here? The super cool devs already added this to a newer version of the client viewer. Go there. Enjoy it..... but thanks for reading.

Tuesday, January 17, 2017

Bullet Jumping - Neo Style

Update:

I think Aakif Aslam is correct, I think this has been nerfed. :-(

Pro-Tip Probably Straight Out Of The Matrix Movie

Have you played around with jumping over bullets? I believe this little "hack" still works. In theory your bot can move directly towards a bullet that is coming at you. If you time it correctly you will never collide with it. You could stride right over it and never take damage.

The major downside is that often so many bullets come in a row you don't have space to land between them. So you are going to have to look ahead as far as you can. Tough to pull off but when bullets aren't flying continuously at you this could be helpful.

Countering Neo

Wait. Why am I using Matrix references? There was a really horrible movie called Jumpers or something like that where people could think of another place and teleport there. Ok, surly, that would have been better but I'm already committed to this mistake so deal with it. That's right, I said deal.

Haha, I did have a point I guess I should get back to that. Ok, so if you want to counter the Jumpers, I mean the Neos, then think about placing your bullets one after another timed so that if Neo isn't looking far enough ahead he will always get hit by that trailing bullet. Pretty easy to do because it's what most players would already be doing in general even if not for this specific purpose.

How To Do Well In The Sprint Tournament

Tick-Tock

It's Tuesday night, less than 24 hours left to get your bot working for the sprint tournament. So what should you focus on? How can you boost your chances of winning? Well, there's nothing to it but to do it. Cut off social media and other distractions and just get to it. Turn on some motivational music and code it out.

Polish What Works

Anything that you have working at this point is going to help you. So polish it off. Optimize it. Test it a little at least before uploading, it's better to keep something you know works a bit than to chance something untested at the last minute that might be broken. Check for the little things, are your troops still shooting themselves in the foot? Move and then shoot, that way you don't run into your bullet. Throwing exceptions? Figure out why and fix or prevent it.

Everyone always wants to find that one million dollar idea, that one big thing, that is going to fix everything and make it a turn-key deal. That's just not often the case my friend. Work hard, find the pennies and they will add up much quicker than you think. Just keep doing all the tiny fixes you can find and get them operational quickly.

Trim The Branches

You may have those big ideas that just haven't completely been implemented properly... yet. That's ok don't throw them out. If you are using version control, which you really should be, then branch off and come back to work on them after the sprint is over. Commit to what you feel most confident with right now. Better not to have crazy code going awry and to have less features that actually do what you want.

Best Advice You'll Get Anywhere

Ok, so you feel pretty good. You have your bot bashing everything you can throw against it. Congratulations my friend, but don't sit comfortably on that now. Now is the time that you need to start thinking outside of the box. Think for a second... what assumptions have you made about this game that aren't really in the documentation?

Did you assume that all maps would be square N x N maps until you saw "Line of Fire." It's okay, you don't have to admit it here, but that's the kind of thing I am talking about. Figure out what you are over looking and making assumptions about. This could likely be that tiny edge your bot uses to win these unseen sprint maps.

Out think the developers and figure out what assumptions are going to leave you missing out on huge potential advantages and which one are just going to break your bot. What if you spawn with only enough room to build a gardener and a lumberjack? Did you think of that? Will your bot handle that? Surely that isn't very likely but what else is lying out there in wait to bring your team to a grinding halt?

Can You Handle Over Powered Bots

Scouts. Scouts. Did I mention scouts yet? Right now they seem to have a clear advantage over everything else when used correctly. Have you found out how to protect yourself from them? Have you been using them correctly? Make it happen captain.

Procrastination

Planning to work until the very last minute? Hoping the server won't be bogged down with uploads then? Good luck with that. Why not go ahead and act like the deadline is an hour or so sooner than it is just to be safe?

Stop Wasting Time

Yeah, reading this blog is not helping a lot. Lol, not this close to a deadline. So stop. Go back to working on it. If you start to get stuck or aren't making progress for a while step away for a minute and then come back and hit it hard again or switch to something else and come back to it.