Showing posts with label programing. Show all posts
Showing posts with label programing. Show all posts

Sunday, September 9, 2012

busy life little posts



Not much to say here. I've gotten some dungeon generation code down that I like and works... most of the time. Right now it's step on switch and somewhere a wall moves so that you can pass and go forward. It's rough around the edges but it has some potential. Right now there is a bug where sometimes rooms will magically disappear and link wrong by overwriting a doorway so that you'll walk into the room and walk out of the doorway you just went through to enter an entirely different part of the dungeon. Effectively this makes it so that you can't go back past that point as the doorway that did it was replaced with another one. So fun times trying to fix this bug. For giggles here's a screenshot. I have arrows added as a shift + directional button and may use this as the standard for ranged attacks. I also have FoV made because I thought I could hack out something and well I did. Probably won't be in Legend but it was successful programing. Also added is a menu system to the left, not sure if it'll make it to the game but it was something to try.

mostly explored room
Room east of first one with 2 switches
Stepping on a "switch"
Firing an arrow at the fake door

Saturday, November 26, 2011

Neural network and work

The past week and leading up to thanksgiving has been a odd at work. They have decided to send me down to Colorado for some training as the software and my workload was sorta put on hold with preparing for this, they don't want me to start a project I can't finish before I leave, and some coworkers taking time off causing the things I could do to be a little less even though I'm at the tail end of most of the project I have. So this left me with a lot of time to think as I document and cleaned up the code and I decided to on break take up setting up some neural networks on my thumb drive.

I won't go too far into neural networks explanation as there are wikis for this. I have a bit of story on my interest in neural networks and other such research based programing though. In college I sat in on a Genetic Algorithm class for fun. I had an interest in it as I actually did some of my own exploration of it in middle or highschool after reading something in some magazine. I was using game maker way back then and doing some messing around in that that actually had some minor results, most of them being the agents evolving to find holes in my test area or simulation. Either way back at the class I was sitting in I learned a lot about them and learned the basic feed forward neural network. I had taken to making one and trying some things that hadn't been done before to my knowledge and have the neural networks learn to play tic tac toe by "learning" off each other.

This wasn't typical neural network training as I was just using the neural network to preform the work and because the concept of them seemed neat. The workhorse was a genetic algorithm picking and mutating wining agents every generation. This didn't quite work, there was something akin to subspecies in the code that more or less played rock paper scissors with each other. lets say there was 3 groups (that's what I sorta came to believe watching the games) group A would try and win diagonally, group B would try and win horizontally, and group C would try and wind vertically. The game was more or less decided on the first piece as each group had a very entrenched first move after an A agent would place it's move a B agent was basically give up and just fill in the board in a pattern that let A win, a group C would continue as normal and end up blocking the A agent while winning. similar relationship between group C and B. This let each group get enough representation in the genetic algorithms choice of fittest agents to have them represented in the next generation, which just leads to the same not really solving the problem and keeping the agents in equilibrium.

I haven't touched this problem in years but I was thinking about it on work, and decided to get some neural networks programed on break. Took a week with a lot of messing around but I got the agents to solve XOR and inverting the input which is my standard for a working neural network as I don't know too much about standards for these. I also made a "produce key" feature which allows a string to be made based on the weights and thresholds of the agent. This is actually very important to what I'm going for. While not completely versed in the genetic algorithm or neural network programing I've seen that it's kind of been leaning far to a naturalistic side of survival of the fittest. The fittest agent is taken and it has offspring that may be exactly the same or slightly different than it which does work but seems to be inefficient and leads to cycles of not solving anything as I've seen before with the tic tac toe test. So with this key I'm able to keep a "gene pool" and see if the offspring is  worthwhile of being put in the next generation in regards to solving the problem. I may be wrong on this but my learning years ago didn't go on about pruning the genepool and making sure every agent is unique. So right now I have a working neural network and a will to try and revisit an old experiment and possibly produce something of worthwhile research which is some fun I haven't had in programing in a while.

Saturday, October 29, 2011

a roguelike update?

So after weeks of doing nothing with it and playing with other Tkinter components I present.

It's an update. Not the best one and actually glitchy. There are quite a few things I don't like about it but following the ideas for making a roguelike I shouldn't be so hard on myself.

First is that it's hard coded, the 5 lines you see there are positioned there, I'd like it to be at the bottom of the viewable screen. This could possibly be easy to do but I was tired when I finally finished this up so it got hard coded to see it. Not something I should beat myself up over but I like dynamic structures, it helps for changing layouts later.

Second Tkinter canvas centers blocks of text. I do not like this at all. I may have to write my own code to properly justify things to the left. Not sure why Tkinter would think this is a good way to do things considering it works on standard top left coordinate scheme but it's the reality, maybe there is an option to do it that way.

Third it doesn't work. It fills out fine until the sixth item is hit, in which it should "push" all the ones before it up once and the topmost one into nothing. Right now it doesn't do that and I didn't get into the guts to find out why.

Fourth odd glitch. Players will hit themselves after moving on their first spawn. I do not know why but only noticed this with output.

Now for the nice things.

I got it done. It's progress. More than that I discovered a nice feature, with the way I have things move and attack each other enemies moving into each other will attack. This lead to some very confused minutes when I noticed this but it works exactly as it should. I would just need to add in some triggers to count allies as walls for movement purposes to avoid friendly fire, for now it's funny.

Wednesday, September 28, 2011

Functionaly mad : Playing with snakes 5 slither harder

Been a while since I've touched on this so here we go playing with snakes. For this one I'll be trying my best to explain what is seemingly a confusing subject, functions and scope. I would just do functions but scopes and functions go hand in hand. There is one thing they are very useful for but that's more advanced and saved for later.

Functions are very useful for programing in python. First they cut down code. For instance you could write.

print (1*1)+(2*2)
print (2*2)+(2*2)
print (4*4)+(2*2)

Yes I know there is inbuilt things for powers but might as well go whole hog here

 So the age old A squared + B squared to get a number that would be the last part of a right triangle. Lots of finicky stuff you do over and over while being easy to screw up but there is a simpler way and it's called a function and you can write one in the shell. Write the following

def right_triangle(a,b):
Now with annoying color
 return (a*a)+(b*b)

Hit enter twice and you'll be back to "ground level" in the shell. Now we're going to have some problems here due to blog not doing tabs right. Python for functions and scopes require indentation with whitespace, for blog code I'll use spaces, for real coding my preference is tabs. Either way I'll include what I did to the right so I can explain it a bit with graphical aids.

First you have to use def, underlined in red I'll explain why it's important latter, to create the method. After that is your methods name, it can be any thing as long as it is "one" continuous block of characters and avoids some special characters. Dashes are fine though otherwise not so much and I haven't tempted fate enough to learn the results. A space after that is your parameters or arguments underlined in green. In it's simplest form you can use as many as you want or as little as you want, even none you just put (), but you have to give them a name like any other variable and separate them with a comma. Trailing this is the colon which is the first indication of a change in scope. What this means I'll get back to later.

The right_triangle method we created is rather simple. It only has one line of code after it with a return statement followed by things I underlined in yellow. I'll get to that in a second but first lets use the method. Please type the following.

with the power of cropping you'll not see the mistake!
print right_triangle(1,2)
print right_triangle(2,2)
print right_triangle(4,2)



Admittedly this would be more impressive if the text to invoke right_triangle was less than the straight up code with the numbers that it produces. Methods allow you to reuse code and return results. Before there was the underlined piece of code with the variables a and b in it. The a and the b were the arguments passed when right_triangle was invoked in the code. The reason you have to use all the variables is that the code expects them. In the scope after it a will effectivly be whatever is passed first while b is whatever passed second. Now they don't have to be named a,b,c or any sort of sequence. Like the functions name you can name them whatever you wish as long as you separate with commas and enclose with parenthesis.

Now this doesn't have to be one line long. It can be multiple lines as long as the indentation is correct. For example.

The red line is what I called "ground level" for the code. This is where we've been typing everything out. Variables can be used and changed after we type them but now the rules are changed. Inside the function is a different scope as seen by the blue line. It is indented one more than where the def is, hence why I pointed it out before. The arguments passed through the parameter will only exsist as the variables in there and any new variables made inside will only exist until the scope ends. Scope ends by the indentation returning to normal or return statemtn is used, regardless if it returns something ro not. This functionality of return will be important later but for now it's just a neat trick.

Now this wasn't a very useful function. As I said before you could type out what it was doing in less typing than it took to make it, but once it starts getting lines long or used for other things that involve later ideas it'll start looking like a good choice. Till then hopefully I didn't butcher this idea too badly.

Wednesday, September 14, 2011

progress and doodling

I think I have my variables double checked now. Even noticed a glitch with the attack tags which I fixed. Now I need to do a few more tests and finish up implementation of AI punisher move use. After that some difficulty check and I'll just have this test be "pick a guy and beat him up". Not too involved but should be a good test to see if this idea was worth it.

Other than that I've been trying to do some more drawing and revisiting some of the things I used to do. There is a little exercise that we had in class doing "gesture drawing". The basic idea is we get a model or have a picture shown via projector for 30 to a minute and we try and get down as much as possible. Mostly an exercise for few but accurate and descriptive lines as we can't rely on a model or a scene staying the same for any extended amount of time. I did decently well with this sort of thing, in fact before formal classes I used to do something I called ten minute drawing with some guy I knew online.

Basic idea was we'd throw the other an idea and see what we could get done with it in ten minutes. Results were usually laughable and over ambitious but I always found it good practice. Tried doing some last night with friends and while the results were laughable it was good to get back into the habit so I'll see what I can get done later in it and with some gesture drawings nightly.

A tool I have abused is this site. Posemaniacs is from what I know an English translation of a Japanese site. it has a lot of 3d render models of mostly a muscle layer in various poses for both genders. The thing I used the most was the gesture drawing tool of "30 second drawing". This was practicalyl made for testing your gesture drawing skills as it will go for 30 seconds than instantly change to another random picture from it's library. I've seen a few around that do this but I like this sites. You can even shorten or lengthen the amount of time up to 90 seconds if you are just getting started at the whole thing and don't have a teacher to yell "stop" and force you to draw quicker.

That's about it, any of you doodle in your free time? Or if you're particularly brave/bored apt to throwing a link to something that you throw down in the 30 second drawing flash ap.

Tuesday, September 13, 2011

debuging and things that could use some debug

I think I found the first of my problems in combat test. Good old variable mess up. For example block has a block_wait and a block_change and parry, and dodge have similar. The X_change is how many turns at max it can wait to change and block_wait is the actual counter for it. Easy change but showing that you should always make variable names you'll get exactly what they mean on viewing. So going to work on fully testing that out and getting the AI using punisher things itself.

Other than that my Friend finally got me to get the minecraft pre release files as we could try out a server. That didn't work too well. For whatever reason I would log in, load for a while, move around ineffectively then get timedout. Seems to be a reported occurrence with no real work around so we're left with rolling back to stable version until a real update comes out. It's annoying but it's something I can expect.

Though I did make a single player world. Which happened to be an island. With one tree. No farm animals spawned but there was some tall grass. So after carefully harvesting the tree in hopes of saplings I made a farm. From there I hit tall grass for seeds to receive one. This did not seem good with the newly implemented food system. So I left the island a bit to find a few other small islands with tall grass and nothing on them and returned to plant it and do some tree management. Before the wheat was fully grown I found out that you can starve to death in game, now I made the mistake of jumping into the ocean to see if I could get in the seemingly glowing holes at the bottom before I died which I didn't make it too. This messes up my evaluation of "Starving" because I swore it left me at .5 a heart before suffication under water took that away, but I could be wrong.

After that I made another world with more trees and the hunger problem came again. I had plenty of sheep around and got lost getting other meats through hunting. Raw meat I found out does next to nothing for hunger which proved anoying when I started wolfing food down on the last food indicater. Though I have a little wheat farm growing in the middle of a lake and want to get some pumpkins or watermelons to see how they work in game.

While buggy as hell I'm actually very interested to see how food will now play in the game. I also want notch to leave the option of "classic" play style where food doesn't matter but I doubt that'll happen. It'd be a shame though, as he did say there would be ways to ignore food and Creative omnipotent mode isn't quite the way to do that.

Friday, September 9, 2011

Random musings

Yesterday went well thought this week is seemingly wash for Combat project so I'll extend the projected date a week and take it easy this weekend. So just a bit of random musings.

Though I have found out a few things about python. I managed to get multithreading working though it seems the python language is not the most thread friendly language. I managed to use that with a bit of socket work for a simple echo server test. It was interesting to do something that had some non game programing.

I have done work in other languages in a higher end capacity but python has mostly been my personal amusement code. Simple little programs or games of no real value to anyone else. It's easy to transport, quick to set up, and isn't too much of a pain to work in beyond self and whitespace issues so it works well for that. On the professional end I have no code in it, and that was what the people were looking for the other day.


It was a little rough but at least it was something to show the people who were interviewing me along with some older code. It could use a lot more polish and I did cope out with some timeout functions instaed of perfectly avoiding deadlock which would only appearing in 4+ thread cases where something would get stuck on listening for a reply. I considered it a win though getting it all done in one night.


While on that subject, have you guys done anything quicker and more proficiently than you expected when you needed it?

Wednesday, September 7, 2011

further delay on anything interesting

It seems I won't have anything interesting today to offer either. After some poking around I got a quick interview to show up to. While this all well and good I have little current programing examples. To remedy this all day I have been producing some newer examples of my competence in coding.

Namely some multithreading and server client code. Then combining the two. It's going along decently well as this is territory I have covered quite a bit in my schooling days but I have never done it in python so there is a few language hurdles to overcoming though hopefully it'll help out in the end. I may attempt to get some SQL examples done but I don't think that will happen if I want sleep.

Tuesday, September 6, 2011

ai brain problems

Took yesterday off to play some games and check some job things. Though today I have been hitting the code hard for the past few hours. In those few hours I've set up all the variables and have been starting to test the ai defense switching in response to getting hit with attacks that punish it for the defense it's in.

variables variables everywhere and I'm this close to needing to watch all of them
The above image is all the default values, I'll be making a monster creator method to tune them to values needed. As it stands it's both due to me trying to do too much at once and not planning correctly. There are probably quite a few things I could reduce or find a more elegant solution to implement but it's eluding me. Though I will say that I did discover a bug in my previous tests as I was only using the default randumb AI pool on accident and that was sorted out.

I'm unsure what it is at the moment due to my AI being a mess of variables. Sorta stumped and more than a bit frustrated though I'm slowly worming my way through it. Not much else to say beyond tomorrow I'll try to think up things more interesting to say. The situation at hand is taxing me a bit and I have some mundane things I was going to work on as well as this that are leaving me a bit brain dead for writing an interesting post.  So nothing interesting till tommorow.

Tuesday, August 30, 2011

Building a better brain

Not much to say but making this quick.

I've come up with the basic functions of the AI. For the most part It's driven by what type it is which sets some of the initial variables. Easiest thing to set up is percentage of each pool goes into pool. Each pool has two numbers per AI type. The first indicates how many it takes, second indicates the face of the die it takes. I didn't want to make it complicated so face is determined by lowest, heights, and random which just takes anywhere form the sorted dice list. Hopefully this gives the monsters a somewhat knowable action without you being able to always predict it.

It's defensive set up may change from round to round just like the players. It may have a favored defensive set up that when it hit with a punisher move for it It'll shift to a regular dodge periodically if you try to repeatedly use it. The only problem I see here is that punisher moves do a lot of damage, so much it may be a bug and I may have to bring out the debug code just to double check.

After that is it's own use of punisher abilities which I have explained before. Though I will give a brief explanation here. The AI will roll some dice when it sees  a defense used it is allowed to exploit, if it sees that again after the rolled turns it will set up the edge ability in one or two turns. This may have a few holes in it but I don't want teh ability to just chage defense every turn to negate the enemy ability to use edge abilities, IE it sees you used block so it prepares armor breaker next turn which you use dodge where it does nothing and then you go back to block repeating the cycle and just making it use edge for no reason.

Other than that it's coming along decently. Going to try and get down the rest of the basics in the AI class tonight and see what tomorrow gets me to do.

Monday, August 29, 2011

To AI and beyond

Well finally figured out what my problem was. After getting tired of looking for the print statements manually I just used find function to scroll through them out. It seems I had made a debug method inside the charcter class to display all the pools and this is where the debug spam was coming from, for some reason I could not see the debug in character_debug_pool_list() unless it was commented out.

So that is taken care of for now. Now I am working on a more inteligent AI system. Currently in a text file is some mental sorting going on about what variables I should have and what basic procedures I should go through. This may develop into it's own class but I'm not sure yet.

The basic idea is to let it "see" that someone is blocking then possibly use armor breaker later to maximize damage on the player. The same is true for the other punisher moves. This leaves dice pool manipulation up in the air, but I'm not sure if I'll even be having that for most monsters. So far it's getting organized and looks alright but I'll have to start testing it.

Beyond that is actual demo. I can simply set up "choose from this list of monsters to fight" and have that sort of demo. It'll work but it seems a little cheap. I should at least try to turn it into a simple game of sorts, maybe even have some leveling up as it is a RPG but that is for later. Though thoughts on it is ever X levels gain another dice to roll and maybe just standard +1 hp per level. Maybe even throw a weapon or two in there for increased damage.

Wednesday, August 24, 2011

AI concerns and clean up.

Entering in the punisher move for bonus against parry and thinking about AI while generally cleaning it up. Not much to say about it so I'll dive into what I can discuss.

The current thought is how is the AI going to have and use edge abilities. For the most part they are specialized and require some "thought" behind them in use. One thought is that it can "cheat" and just have a timer to see if you stayed in a defensive position for x turns. It's simple and effective but unsatisfying. I don't want to make this too complex so I decided having some random dice maxes based on what type it is. Give it a chance to suprise a player while having a tendancy to lean towards one type.

Beyond that I think I'll have the AIs picking pools be very simple, possibly stupidly so. At the moment I have little idea on what is the best strategy for going about an turn though some ideas have been thought of. It's a start at least.

Saturday, August 20, 2011

Quick update

Due to family things and the game later tonight I'll just be putting up this quick update.

Currently have been coding in Combat Test Project to get the counter effect in the parry defense. After some viewing of how the "make attack" method has bloated I decided I need to trim it down and separate it into useful components.  Got the bare parts seperated to allow counter attack to work.

For counter attack I've been stuck on for a while. It's a passive effect that comes along with using the parry defense type. For a while I've been struggling with how to implement it, the basic idea of this engine was to allow you a lot of control of how you defend and attack. The first blush idea was to allow a new smaller pool to be rolled from the successes on the attack but that seemed random. Going off the defense pool seemed silly and going off the attack pool seemed a little too much of a guarantee of a second hit if you're on the offensive.

I've decided to just take the solution of using the attack pool with some penalties to it. It's not the most intersting solution but it'll work for now. As it keeps turtling strategies to a minimum by dividing up potential defense pool dice.

As for next steps I need to get this attack method cleaned up. This means separating all the bonus and penalty searching into multiple methods which is a chore. Though for my piece of mind when working on this it needs to be done.

Thursday, August 11, 2011

Combat check list

Well I have been getting a bit lazy on the Combat Test Project work so I'm going to rectify that. So today a little check list for getting this to completion. So a simple little list centering around what I should focus on.

  • Engine
    • Basic engine DONE
    • Useable I/O DONE
    • Modular and expandable use
  • Abilities
    • Basic attack DONE
    • Attack Options IN PROGRESS
      • attack degrees USEABLE
      • Punish abilities
    • Defensive options
    • Dice pool manipulation abilities
  • Enemies
    • Basic AI DONE
    • Not dumb AI
    • Actual enemies
  • Usability
    • Mistypes do not cause crashes
    • Normal people can navigate menus
    • Not annoying
  • Unwinnable things
    • Bugs
    • Tested balance
    • Insert fun
    • Good tune up
So looking at that, not too horrible. Not too good but it's something to start working more on. Engine for all concerns is done. Unless I want to do all the unique hit descriptions and such it suitably works right now. Useable input output is for testing purposes, allows me to test everything and see results. this means debug code everywhere that I may have to edit out later. Modular and expandable use is already underway. I have this entire system setup to allow multiple monsters or playing characters in theory. In actuality I don't think it'd work well for players as it's all keyed off a single Character object. Though it is feasibly changed later, or even through array use.

Abilities is where I want the real meat to be. I currently have a small list of basic modifications and a few choice abilities to use that I don't think is enough but is "enough" for testing purposes. Punish abilities I need a few more of. Defensive options are nearly done as soon as I figure out how I want counter to work. Dice pool manipulators are half finished as I want to do the defensive portion of it now.

Enemies is a bit of a struggle. I may keep them at randumb as I call it for simplicity sake but I want some chance of it avoiding punishing moves and using them on the player which will get hard. Nothing too complex and not completely random.

Usability is one I'm not too keen on doing. I'm a very prototype making person, right now this is "useable" even with all it's input errors and befuddling menu loops. Right now it's the very bad state of needing to know what you're doing, something I hope to fix when I throw it up on here.

Unwinable list is the programers never winning portion. Bugless code that works right in all instances and does what it's meant to do. Combined with my own ideas of what it should do it's there just to remind me to go over it more often, I'll never find all the bugs nor will I get ti perfectly balanced. I just have to try for it. Good tune up will be me making things less spaghetti code, the attack method right now is laughably large and needs to be broken up into methods. How small of methods is the unanswerable question for me.

Thursday, August 4, 2011

Checking it twice : Playing with snakes 3

Currently house sitting again, for other family members, for other animals. Funny how being unemployed comes with perks of getting picked up and dropped off then told not to burn the house down. That aside I was thinking of continuing my playing with snakes tutorial today with basic loops before realizing just how python works. Like it or not I find this somewhat therapeutic to go over basic programing things so I'll be doing this till basic fighter is done. So with that, lists in python.

If you are familiar with other programing languages you may know the concept of arrays. Python has a similar concept that is effectively used in the same way but there are some very key differences that would take too long to explain. Effectively a list is a collection of variables, that are able to be called up through their 'position' in the list. Array deceleration, assignment, and use are slightly different than regular variables so I'll explain by showing. Please type the following.

alist=[1,2,3]
print alist[0]
print alist[1]
print alist[2]

A list is made, and then broken

Lists are signified by the Square brackets. Inside is each "item" in the list separated by commas. So this list is assigned to the alist varaible, and inisde the list is 3 items of 1,2, and 3. We are using intagers for this but anything can be put into a list, just like anything can be put into a variable. In fact you can mix types up in a list if you feel so inclined.  After that We start manually printing out the items in the list starting at index '0'.

To call an item from a list you place the index you want in square brackets immediately following it. That simple. Now you may wonder why this is worthwhile but when I get onto loops and other such controls you'll see.

Now this is where quite a few errors turn up. Humans like counting starting at 1, computers like to start at their location. I could get into the philosophy about this but that could take a while. For now remeber 0 is the starting position.

The other thing to note is what happens when we ask for the '4th' item in a list of 3. We get an out of index error. This is a bad thing, not as bad as it used to be. In the older days and in other systems when we ask outside of index we are getting unknown data that was right after the array or lists memory location. A pandoras box of unknown things that may be other variables, left over data from previous allocations, Other processes in worst case, or who knows what else. Nowadays we get errors and the program crashes to save us from ourselves. Because of the fact we would like to know the end there is a simple solution, we ask for how many items are in the list, we do this easily by typing the following.

len(alist)

By using the method len and passing along a list we will get the number of items in the list returned. With this we know if we ask for that number or higher we'll have bad things happen. Now another thing that is useful to know. We do not have to individually go through the list, we can in fact print it out in a format. Like with numbers we can use the str function with a list passed to have it printed out as a string. Try the following.

print str(alist)

With that you get a result much like if you were to set up a list. Now one last thing I would like to say about this before ending. Python has a method that produces a list of numbers, this is the range method. There are a few differnt ways to use the range method but we'll just use the most basic. Please type the following.

blist=range(3)
print str(blist)


Like this range produces X numbers starting at zero much like the index. So it will produce all the numbers from 0 to X-1 where X is the number you put into the method. You can do more fancy things with it but I'll show that latter.

With that out of the way I guess I can ask two things. Any of you out there have programing experience? The other question being what things do you find relaxing that seem odd?

Tuesday, August 2, 2011

Ahead of the curve

This slightly relates back to yesterdays horribly long post. Only it won't be long and it's less ranting and more about Combat Project.

So currently initiative in combat project is based on taking X dice from your initial pool. Or none at all for a zero.As it stands I've found it quite useful in these testing runs to put nothing in the initiative and put that die in attack or defense. This seems cheap as right now the  AI always puts a die in the initiative pool making you effectively have one more die in exchange for always going second.

The first idea is to force the player to put a die in the pool. This seemingly goes against my idea of how much control you have. If you rolls were too high and want to go second you're left hoping the AI put a higher die in the pool. The second idea is expanding on the edge system. Having a "first strike" attack that allows the person to get a bonus of some sort on the target, what yet I'm not sure either damage or bonus to hit which can easily translate into damage. This is probably going in one way or another as it is a risk move for the player too. They could pay for this and put in their greatest die or dice to guaranty going first at the expense of attack pool or defense pool. This adds a bit of risk reward in setting it up as it took some edge and now it takes you hoping to get a first hit. Third is, multi attacks.

Yesterday I discussed the main sins of multi attacks and am very weary about putting it in system. Namely just how much should an extra action cost and if a character will just pay that and nova with it and other edge abilities. Allowing more than one attack a turn also opens another can of worms here, as the attack bonus has already been set so either nothing new happens or more damage is inflicted. This said the basic idea was that if you have twice the initiative of the opponent you would go on your regular initiative and then once again at the end of the round for another regular attack. This does once again attempt to force you to put a die in the initiative pool but it is giving you a choice. A poor solution possibly but it does allow you to put a lot of initive in the pool for hopes of achieving the double attack result. It may even be a good edge idea but for now I'm going to think on it.

Thursday, July 28, 2011

Bugs and coding

  
Bugs, from this lovely site for getting rid of them
So after yesterdays coding tutorial I decided to work on combat project. It was a very fruitful endeavor in one way. Discovering horrible horrible bugs.

So I was working on spirited attack idea. It was an effect that happened when you attacked an opponent and manipulates their attack pool. It plainly removes the highest die that is under twice the edge you spent. I was going to allow multiple purchases with it, but for purposes of getting this done it's only one die at a time. Still if you pay enough you will get 1 success, possibly 2 removed from their pool which is very useful. Latter I'll put in one of two systems, multiple values to keep track of just how many dice and the values you are trying to remove or allow you to take multiple dice of the same value. Second one is easier to program in some regards and I like how it forces you to choose what dice to use instead of throwing as much edge as you can per turn to pick off dice. Either you choose to stick with low numbers and risk it taking no dice out, or you pay a lot for higher numbers.

This said it was looking good and I implemented it well. A few problem like not actually reducing edge points  a few times an a math glitch but nothing major. This was until I saw how the hit system was working.

The current system is that attack value and defense value is tallied between the ones engaged in battle. This is done by calling some methods with modifiers to the TN number on both sides and simply using subtraction to see who won. So it goes attack_success = attacker tally - defenders tally, if attack_success is greater than 0 it's a hit. Everything seemed fine until I looked at the method.

methods can pass variables by putting it in  between brackets. If you've done some math functions such as x(y) comes to mind. In programing you can stack this so x(y(z)) can happen. I made an error of forgetting a bracket running the code and getting an error saying I forgot a closing bracket, mindlessly looked at the code and slapped it after the defender tally method, containing it with the modifiers for the attacker method. This effectively made it so that the attacker was getting a bonus chance for extra successes based on how well the defender defended. A big whoops and invalidating a lot of how I thought the system was working.

So that's fixed and I'll be double checking it more, I may also think on solving some menu problems soon, because hitting enter a few times to skip over edge when I don't want it is anoying. One solution is to make a variable to serve as a flag if the user through the edge command sets it, without it set edge donation won't appear, but that seems rife with possible annoyance if you forget to set it, then after you get your edge you want to unset it. Possibly not the most elegant solution. Since I am using terminal based prompt I could include the flag in choice typing. Enter the action selection followed by a  - and you skip edge. That is for later though, I have to see if my system is fundementally broken after bug fixing though.

Wednesday, July 27, 2011

Variable Fighter : playing with snakes part 2

I feel in a programing mood today so I'll be continuing the playing with snakes post I made a few days ago. Last time we played with some input and output in the shell. Today we move onto some variables garnished with a little scope concept.

First thing first, if you hated algebra this is like that only you don't have to solve things. You get to say what x is and everything else bends to your will. Though if you name your variables x you are going to make anyone who reads your code cry. So first thing first there is a called typing for variables. Where a variable is of a certain type, such as a string or int we used before. In other languages you would need to declare variable types, for instance in C languages you would do things such as 'int your_int" or "string your_string". Once the type is declared it won't change, if you try to assign something else it'll cause an error.

Assigning is the basic point of a variable, just having a type there makes it sort of pointless. It's very simple and as I said before like Algebra but you get to say what x should be. You simply have your variable and put '=' after it followed by what you want the variable to be. It's horribly hard to for me to explain it, so I'll have you do it, and you'll see it.

So get IDLE up and running and type the next few things.

name = "bob"
age = 20
print name
print age

More lines of code than I've ever had you done yet. Before we did everything on one line, now it's over multiple lines. You assigned "bob" to name before you assigned 20 to age and yet when print was called with name after it bob was printed, same with the age variable. This has something to do with an idea called scope. Scope is where variables exist, and where they cease to exist, but I'll get more into that later. Next I'm going to show scope not working.

Please type the following

print date
date = "July 27, 2011"
print date

Didn't work out did it? We got the wonderful red error. Yet we were able to establish the we assigned a string to the date we were able to print it out. Before the point in time where we enter 'date = "July 27, 2011"' nothing exists for date. Nothing. Anything referencing to it before we put that line down it a horrible thing that will cause your program to fail. The only reason we were able to keep typing is because we are running everything in the IDLE shell. If this were actually run as a stand alone program through the standard python interpreter you would not get the second print date to fire off, it'd be dead at the first one. While not a hard concept it'll creep up to bite you sometimes.

Now onto the next thing. Variables are reusable, they don't disappear after you use them once. For instance lets show off name and age again in a worthwhile manner with a little string concatenation. Please do the following.

print "Hello my name is "+name+" and I am "+str(age)

Just like before the str method attempts to turn anything into a string as only strings can be concatenated together. Now lets move onto the next part. Variables are well variable, you can reassign what they contain at any moment. For instance the following.

name = "rick"
print "Hello my name is "+name+" and I am "+str(age)

Bob has magicaly become rick. Now that was fun, lets change his name to Ron.

age = "Ron"
print "Hello my name is "+name+" and I am "+str(age)
fun fact I did something out of order and this is hiding it

No that was not a typo. That was an example of python not caring about type when it comes to variables when it can attempt to process them. Any variable name is fair game to be changed to any other variable type. This can cause a lot of debug problems. Like if you think you correctly changed a variable but spelled it wrong, it just makes a new variable in scope instead of replacing the old one. It'll become a possible pain when I get to objects later but I think this is enough for right now.

Next time I'll introduce the concept of methods so we won't have to type, or copy paste, 'print "Hello my name is "+name+" and I am "+str(age)' so many times.

Sunday, July 24, 2011

Strange weekend and updates.

So cat sitting is done. A little late in posting this because of some things that went on though. Between hot weather, randomly going to family dinners while still being an hour round trip, phone tag, and the usual weekend plans not much done as I thought. Either way progress is progress.

I have put in the ground work for the Edge abilities. Edge abilities use "edge points" or whatever I decide to name them later. You gain edge points by taking dice out of the pool rolled at the start of each round. From there you go about as normal distributing points to initiative, action, and defense. I have two currently in the list, armor breaker and "spirited attack" but only have armor breaker currently working.

Had a long list of debug problems that popped up and while stupid were not easily solved. Mostly my fault do to me putting down a lot of code without setting up something to test it, so a few mistakes compound and become somewhat  harder to find. Anyways a bit about the idea of the edge system.

The edge system is yet more tactical choices in battle. The thought is that if used properly it can let a well thought out battle plan take down a powerful foe or allow a character to lose less resources through battles.I don't quite want this to be a "spam your largest move" system but still have some major effect in game. So the edge points starts out empty at the start of every battle, filling up the pool is risky as it takes away from the rest of your pools. In fact you could fill up your Edge points quickly if you leave yourself vulnerable which adds to strategy and risk vs reward thinking. Currently on the idea list are punishes abilities and general pool manipulation abilities. Punishes abilities punish the opponent for choices in defense or attack, so if you think you have the foes strategy down you can tear it apart. Though since this isn't a player only system with a little AI I could possibly keep a player on their toes if they try to abuse certain aspects. The other is pool manipulation, at first blush I have two ideas for it.

The first like Weapons of the Gods idea of floating the dice into the pool seems natural, though it may be a little too powerful with no restriction so I'm thinking more on that. After that is modifying the enemies pools. The one I'm currently working on is removing one die from the enemies defense pool of a value equal or less to half of the edge spent to use it. The idea being that a large storage of edge could leave an opponent defenseless for a turn but may be too unfeasible to do it correctly. As these pools use 10 sided dice to guarantee you remove a die from the pool you have to bet 20, if you knew exactly how much the AI puts in their pools you would have to bet 20 per die. No refunds of any sort if you only remove 1s from their pool.

Armor break is currently a type of "punishment" move. If the enemy is using the block defense choice it'll give a better chance for extra successes for the attacker and make it harder for extra successes. Currently costs 5 edge, meaning you have to remove a 5 or higher dice from your pool for the edge pool to use it. This may be making it too powerful. As it stands I've seen it take out the opponent in one good hit more than once. With a little planing I can do it on turn two which isn't something I wanted. It's part of the fact that successes translate to extra damage but it's also because of how cheap it is. There is nearly no risk unless you roll a pool with no die individually being above a 3. So some more work needs to be done.

Though as it stands the attack tags I'm using are working well. Currently when an edge move is selected it appends it's tag to the end of the users attack_tag list then the attack method takes care of searching for them in the right spots for their effects. At the end it empties the list so there is no chance of accidental repeats. I mention this as I have in the past used libraries or regular variables to check to see if they were set, and each individual one had to be zeroed out through a method. I'm unsure if it's faster that way or not right now but due to the fact this isn't a simulation any inefficiency will be negligible hopefully. Either way I should keep an eye on it.

Thursday, July 21, 2011

Reticulated programing: playing with snakes part 1

Well for a change of pace some hopefully useful or at least intriguing information if people were ever interested in programing. So with my current weapon of choice I present playing with snakes.

Image via this website

So as I like to be goal orientated to go about things we're going to make a very bare bones terminal based RPG that my friends had dubbed a long time ago the Fighter RPG. Very basic, no real options, you get to level up and chose some stats to bring up and maybe use some potions. Sounds simple, but programing it is a bit of a challenge.

First things first, you need to download the Python interpreter. For the purposes of me not having to read up on version 3 go with version 2.7. Though I doubt it'll make a difference. I don't believe version 3 broke a lot of code.

For this post I'll just stick with basic output right now. Since I'm not doing anything fancy everything is just text. 

After it extracts and you run it you'll be greeted with the shell. Which will be where we will play with today.
snake skin
The IDLE gui will work well enough to program in and it will give us some syntax coloring. Though in my experience that'll be erroneous sometimes though it'll at least show that it's an important keyword. What that means I'll get to later. For now I'll show the neat thing about interpretive languages. Right now you are able to input code and Python will execute it. For the age old starter we'll do the age old "Hello World" 'program'. To do that you'll need to type the following.

Print "Hello World"

After that just hit enter and it'll execute. You should notice Print and "Hello World" were different colors. Print is a command in the language while "Hello World" is a string, for now we'll just denote strings by the pairing of " but it can be done otherwise. Anything between the two "s will be counted as being part of the string. Print will try it's best to print out what's following after it. For instance you can print out the result of a math function. Try the following.

Print 5+4

You get the obvious result of 9. Now for a tricky part, in most languages there is a concept of  Concatination. Where you are able to combine strings together. To show this off try the following.

Print "Hello " + "World"

The result is the more complex version of Hello World above. What happens is effectively string math. It takes 'World' and 'adds' it to 'Hello ' to produce 'Hello World'. There are other math commands that python likes using with strings but I'll save those for later. Though speaking of math, what happens if we wanted to use numbers with strings? Like print out #1) for some innane reason? Well lets try it.

print "#"+1+")"

You got a big wall of red text there. That's an error, the interpreter has met with something it did not like. In this case I'll skip letting you figure out the horrors of that message and tell you what went wrong. It's an annoying part of python to me but you can not straight out concatinate strings and numeral objects. You have to convert the int, I'll explain what that means later, into a string. So to do that.

print "#"+str(1)+")"

No ugly red text. str is an inbuilt function in Python which I will get into later, all you need to know is by placing something between the brackets it'll try it's best to make it a string. Though this is an academic case, if you knew you were going to need one there you could have had it contained as "#1)". I don't know the best way to explain this but when it's in a string, it's in a string meaning when it's surrounded by "s it's seen as a character and not as a potential number by the interpretation. So you should have something like this.

I think this is week 1 of a computer science course in a nutshell




And I'll leave that as it for today. While not immediately useful it's a glimpse into programing. I may take this to completion faster if anyone is interested though it'll serve as something I like doing, showing people how to program.

Edit: Forgot to briefly touch str()