Sunday, September 18, 2016

Learning any base numbering system

In previous tutorials I made, I showed how to work with binary (a base 2 system) and hexadecimal (a base 16 system). There are many things they share and principals in their systems which are true. Knowing these principals you can derive and learn any base system quickly and intuitively.

The first thing you must realize is the BASE of the system. This is the determining factor in knowing the place value for each digit. For example if we use the decimal system what we count with everyday we see that it is base 10. That means there are 10 distinguishing characters used in this system. These characters correlate to the digits and in actuality can be any character but for this example we will use the characters we are all familiar with which would be [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]. As you can see there are 10 distinguishing characters or digits.

Lets talk about place values now. Given any base system each place value to the next is calculated by (BASE ^ PLACE).

So in the base 10 system its like this:
...... 10000(or 10^4), 1000(or 10^3), 100(or 10^2), 10(or 10^1), 1(or 10^0).

so given the decimal(base 10) number 54,321 we can see that there are:
5x10000 or 5x(10^4) = 50000
4x1000 or 4x(10^3) = 4000
3x100 or 3x(10^2) = 300
2x10 or 3x(10^1) = 20
1x1 or 1x(10^0) = 1

if you add these all up (50000 + 4000+ 300 + 20 +1) you get 54,321.

Now lets try duodecimal(base 12).
Lets establish the characters [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B].
(where A can be thought of as 10 and B as 11)
now establish the place values.
.......20736(or 12^4), 1728(or 12^3), 144(or 10^2), 12(or 12^1), 1(or 12^0).
so given A53B7:
Ax20769 or Ax(12^4) = A0000
5x1728 or 5x(12^3) = 5000
3x144 or 3x(12^2) = 300
Bx12 or Bx(12^1) = B0
7x1 or 7x(12^0) = 7

if you add these up you get A53B7.

because every system is base based (lol didn't realize this pun until I wrote it) we can just divide the the bases to go from one base to another. using the remainder as the desired next digit in the resulting base's number.
One way is to do long division with the 2 different bases and help with base 10.
I'll get more into converting from any base to any other base in my next post.

Monday, June 20, 2016

VBES - Saving even more bandwidth with UTF8

So a while ago I came up with an encoding scheme which utilized UTF8's variable byte concept to essentially save bandwidth while chatting in instant messaging scenarios. After that I had thought of improving upon that idea even further but never got around to actually coding it, I had the idea down but I didn't have a solid working scheme much less code. The other day though I thought I'd work on it and after planning it out and finishing the encoder and then the decoder the next day I had come up and made an encoding scheme which meets all the requirements of my previous encoding scheme and performed better (in saving bandwidth). This new scheme implements the idea that some letters are used more often then others and so if I allocate fewer bits to those more likely used letters the final message should be pretty small. I broke up the letters, a few punctuation, a space and an escape for UTF8 fallback into groups of 4bits, 6bits, 8bits, and 9bits. It is completely backwards compatible with UTF8 which is nice in scenarios where VBES would produce larger messages, one can just used the UTF8 version instead and the message would still be decoded. Its a simple concept and I will be opting to use this for my future messenger app.

How it works:
* 0000
e 0010
t 0011
a 0100
o 0101
i 0110
n 0111
s 1000
h 1001
r 1010
d 1011
l 1100
c 1101

u 111000
m 111001
w 111010
f 111011
g 111100
. 111101

y 11111000
p 11111001
b 11111010
v 11111011
k 11111100
j 11111101

, 111111100
x 111111101
q 111111110
z 111111111

The * signifies that there is an escape and a UTF8 encoded character should fill the space.

Demo Encoder/Decoder: Download VBES Encoder Decoder

How much space does this save?
In the best case scenarios the size of the message is 50 percent of the UTF8 message plus 1 byte. So that is (X*.5)+1 bytes.

Where does this 50 percent plus 1 come from?
The half comes from the fact that the most optimized characters are 4 bits long which is half a byte which is half the size of the smallest possible letter in UTF8 which is a byte. The +1 comes from the fact that if a message consisted of all 4bit letters and fit perfectly into multiples of 8bits there would still require 2 more bits for the UTF8 marker. With those 2 included bits there now has to be padding and thus an entire byte has been added to the message.

How does this compare to the previous encoding scheme?
The previous encoding scheme worked on optimizing several characters and allocating 6 bits for each of those optimized characters. Because 6 is 75 percent of 8 and also had the 2 added bits for the UTF8 marker its best scenario efficiency would be (X*.75)+1.

How comes this scheme doesn't optimize capital letters?
By default this scheme will turn the entire input message to lowercase because only the lowercase letters are optimized and thus the message would save the most space this way but you can disable this behavior if you truly wish to send a message with capital letters. The capital letters each will be encoded using standard UTF8 and their placement will be signified with 0000 which is also used to signify the placement of other UTF8 encoded characters.

Source (

Open/Free for non-commercial use.

Tuesday, April 26, 2016

Interesting Videos

On the internet there are many sources of information. This post will revolve around videos on YouTube which provided me with knowledge of some form of intellectual interest.

More to come....

Friday, April 22, 2016

Essay Builder

     I have started college again recently (or not so recently) and am nearing the end of my first semester. I am finding myself struggling with one class, English 102 (the research paper). Now this isn't because I hate writing or because I lack the ability to do research but personally I think I am simply lazy to write an essay. When I think of research in terms of gaining knowledge I do just that, gain the knowledge. I do not write things down and I ultimately don't see the need. If knowledge is what I am after and I need a book with me to reference and reread over and over again that simply means I didn't obtain that knowledge (in my opinion). So I had this idea of making a program which makes the essay for me. Now this isn't some magic bullet idea, most of the work will still be done in person like the actual research etc. This program is only going to provide a more seamless and ease the process of structuring, citation etc. I have yet to work on this program and its too late for me to use it on the current paper I am working on but I already have the basic idea and concepts. Once it is done, I will provide it here for people to use so people don't have to suffer from BULLSHIT ass English classes that are ultimately useless in most everyday jobs/careers.


Friday, April 1, 2016

Hacking together a Chess AI

UPDATE: Because of real life and AI being more complicated the competition has been halted until further notice.

     So I am in school again and I have this Java class where I've meet familiar people from years ago. So we have been through this java class for a while now and honestly it isn't all that fun. The algorithms we write are small and not very intellectually challenging. The concepts we have to learn I already mostly know. These days I just walk around class helping others who need it. So I think its safe to say I am bored, oh so VERY BORED. So just recently there was the event of a Go program from google which defeated the work Go champion. The program is an AI which was trained over and over again which means it stores knowledge about the game and plays accordingly instead of say going through and searching through a database of movies or brute forcing the problem. This led to me wanting to do something similar. I proposed to one of my friends from my Java class that we should both make a chess AI and in due time have them face each other in a contest. I eventually persuaded another person to join us. To be honest this was originally supposed to be a connect4 AI but I figured chess would be more fun and challenging. So the three of us are to make a Chess AI and compete hopefully sometime in July. Having said all that, none of us knows anything about programming an AI and thus this is going to be our wits at work here as we frantically piece and hack together a chess AI.

AI cannot have a database of games played (no game look ups), a database of essentially knowledge is okay.
AI is allowed to train during a game through playing.
Games will have 10 minutes on the clock, once that time runs out, the AI will only have 10 seconds to make a move.
Total game time will be 30 minutes per match, if no winner is achieved by that time the game ends in a draw.
If an AI makes an illegal move the game is lost.
5 Games will be played per pair (of contestants).
Winner of the game is determined by best 3 out of 5 but all games will be played.
Winner of the contest is determined by the AI with the most wins among all played games.
If there is a tie, consecutive games will be played, winner is the first to claim a win.
Game will follow these draw rules, but AI doesn't implement this, it just need to know that a game is a draw or when to offer/accept a draw:

More rules maybe added/changed.

Contestants / Implementing Language:
Tim / Java/JavaScript(with extensions)
TizzyT (me) / C#
Dan / C# (maybe Java)
Chris (programming prodigy)/ C#
Phat / Java

Here is some basics I found:

As time goes by we inch closer and closer to the eventual date of the contest. The contest will record every game. The record will include events (moves etc), and the time stamp of each event.

Saturday, January 23, 2016

Introductory to Java

I have started school again recently and one of my classes (for Computer Science) is Java 1. I figure it might be a good idea to make a blog post for it to document and to help classmates who need it. I will cover things in the lessons and explain them in my own way (to help classmates if they so happen to need it) as well as some things I notice, advice, etc. I will try to use illustrations where possible and analogies where concepts are somewhat complex. Also keep in mind that I am not an expert by any means but I thought I would provide this in hopes of people will get at least a feel for how programming is, So while some information for example terms and such might not be completely accurate they should be close enough to use as a stepping stone to reach an understanding on your own that you will develop. Of course if anyone feels as though they need to make corrections or contribute the comment section is open.

[Week 01]
    This week it seems we talked about how a computer system works and how it operates on data. I wont get into much details about that because this is a Java class I don't think this is all that important to know since Java is a high level language. There is no need to worry about things as ALU, or registers etc because they are on a much lower level and programming in Java you will most likely never encounter a scenario where you need to worry about such things.

    Finally towards the end of the first week we got to some code. Although simple there were a couple things we were told not to worry about until later but I feel as though they should have been covered early on so that there is room for familiarity when we do get to them later. We were asked to make a "Hello World" program. This program is typically the first program beginning programs try to make. Keep in mind that I wont be providing code for any other assignments besides the "Hello World" instead I will try to create similar code which will demonstrate the same material.

    Now the code for Hello World will look like this:

    Now there are some other lines before the snippet shown but those wont be important throughout the whole class I believe unless we get into import etc.

We can look at this following code line by line.

Line 1 ("public class HelloWorld {"):
    This specifies that there is a class called HelloWorld. First we have the word "public" this is the access modifier. This states that the "class" can be accessed through the rest of the program. There are other access modifiers like private and such as well and they should be used according to your needs and where appropriate.
Click here to know more about Java Access Modifiers
The next part "class" is usually the Type specifier and will provide information on what kind of thing something is. There are many Types and one can make their own as well. Next we have "HelloWorld". This is a name. This can be anything the programmer wants to call it but typically this should be given a good meaningful name which correlates to it purpose. There are restriction in naming things. You cannot name something that is already taken by a reserved keyword. So words like "String" or "public" will not be allowed. Names also cannot contain any blank spaces in between and to make up for that we have something called CamelCasing which basically has you capitalizing the first letter of each word in place of putting a space. Finally on this line we have a open curly brace "{". In this case this essentially encapsulates the code that will be associated with the class called "HelloWorld", but it will be used to encapsulate code to anything and is used to define the scope. Some people have this placed on the next line but it doesn't really matter as Java is not a line oriented language and so this can be placed anywhere as long as it is directly before the code you want associated with the class also you should pick some convention and stick with it for readability for other people. This easily shows what code is apart of what.

Line 2 ("  public static void main(String[] args) {"):
    The first thing we see here isn't very important in that you can not do this and your program will still run exactly as if you did have it. Its the indentation (the long blank space). Indention is an important thing that one should learn to do as to make it easy for people reading your code to know what level things are at. The more to the right a line is the deeper that code is. The more left means its closer to the general level. Again without it your programs will still work but readability will be lacking and I wont be surprised of the professor took points off for it. "public" was already covered in line 1 and essentially serves the same purpose. "static" states that this is shared among all other instances of the class HelloWorld. You can have a million instances of HelloWorld but they will all use this one main function. "void" essentially means that this is a function which(to the coder) doesn't doesn't return anything back, functions that don't return anything are also called methods. "main" is typically the name of the entry point and where the program begins executing the programmers code. Next we have an open parentheses "(". This is the opening for parameters, just like in Mathematics where you would have a function for example f(x) aka F of x. In pretty much the same idea the parentheses is there to distinguish the function part from the parameter part. Next we have "String[]". In this part there are actually several things happening. First this part syntactically is another Type specifier which was covered above. It is essentially telling what kind of data x is. Here we can see the type is "String". A string can be just thought of as text, so basically a bunch of characters. Then we have the "[]" which specifies that the String is actually an array. You can typically use this along with any Type when you want to make an array of them. So in this case for example instead of just containing one String, this can contain multiple Strings. "args" is the name of the String[] from earlier. This is used for referencing later just like how the x in f(x) is referenced when defining a function, for example f(x) = x + 1. The function name is f, the parameter is x and the function returns basically what ever number you use as x incremented by 1. So if I put in 1 I get 2 and if I put 2 it results in 3. The closing parentheses is used to enclose the parameter portion of the function. Some functions will not contain any parameters and will only show the opening and closing parentheses like this "()". Finally for this line we have another open curly brace "{". This again is to encapsulate anything that is to be associated with (in this case) this function and defines that this is the begin of the encapsulation or defining the beginning of the scope of this function. Scope is the accessibility of something given what level they are on. Remember the indentation. Things on the same level can access each other or on anything that is on a level to the left (as long as it is only to the left, the moment something branches to the right again, anything within that scope that went right will not be accessible).

Line 3 ("    System.out.println("Hello, World");"):
    First we see there is a long blank. This you will see is about twice the length of the blank space from the previous line. This indentation is on another level/scope. This means that anything on this line can access other things on the same scope or anything to the left (in this case things with one indentation). Next we have "System" and is a built in class to Java and has many useful things programmers typically would use. "." is the next thing we see and it is to specify that we are going to reference something that is a part of "System". "out" is the built in output stream object. It is used to output to the console, it is apart of the System class. "println" is a function that is a part of "out". In this case you can think of "System" as some company, "out" is some worker at that company, and "println" is a job that worker knows how to do. Now we see an open parentheses which provides the same functionality as mentioned before. It is there to specify the parameters. In this case (although not shown here) println will be taking in a parameter of Type string. Next we see "Hello World" (including the double quotes). This is called a string literal. A String literal is a string that is used without being assigned to a variable and instead used directly as is. Strings are distinguished with quotes and double quotes. We then see a closing parentheses which indicates the end of the parameters. Finally we see ";" which is used to end the code statement. Because Java is not a line oriented language it needs something in place to indicate and separate statements from one another.

Line 4 ("  }"):
    This is to close the encapsulation or scope of the code block. In this case it closes the function main from earlier.

Line 5 ("}"):
    This is to close the encapsulation or scope of the class HelloWorld.


Comments: Comments are bits of text to note a line of code or note the functionality of a function or the entire program. It can also be used to relay other information as well. Comments can be denoted with two back slashes for small single line comments. Multi-line or block comments can be denoted by beginning with "/*" (without double quotes) and ending them with "*/" (without double quotes). Here are some examples of comments:

Variables: Earlier we talked about String literals and how it wasn't assigned to a variable. Variables are a way of storing things for later referencing/usage. The times we use things such as String literals is when we don't need to reference back to it multiple times and make any changes etc. You create a variable by first specifying an access modifier though not always necessary and can sometimes be skipped. Next you need to specify a variable Type. This can be any of the primitive types such as int, long, float, and double or be specified to a custom Type you made either by creating a class or structure of the same Type name. Next you give the variable a name. This has the same name restrictions as mentioned earlier. Next you can either assign a value to the variable with an equal sign "=" and then close it or just close it without assigning a value with a semicolon ";". Here are some examples of variables:

[Week 02]
    Week two had some basic math and data types. We did addition, subtraction, multiplication, division, and modulus. We also went through unary and binary operators as well as compound operators as well as increments/decrements. Constants were touched on although for me it begs the question "what about readonly" ? It turns out there is no "readonly" in java. Just a mushed together "final". Java seems to be pretty bad if you are trying to do math and with accuracy. For instance in Java it is stated that an integer can store a value between -2,147,483,648 and 2,147,483,647. Now at first one might not see anything wrong with that and I would agree but the problem lies in that there is no unsigned integers. Now this honestly isn't all that big a deal but it unsigned types have their uses. Say we know for a fact that we will never have to deal with negative numbers in our program but we need to store values between 2,147,483,647 up to 4,294,967,295(2^32 - 1). In Java to represent that number we have to instead resort to an 8 byte variable (long) to represent that number instead of the 4 byte variable (int). It is pretty wasteful to allocated twice the amount memory for a number that can be represented with 4 bytes. Of course computers these days have plenty of memory and that is why I said its not such a big deal but it is still a fault and I personally don't know why it was a design choice in Java. Now onto the real problem, lets say we have an integer. Remember that an integer has the specific range -2,147,483,648 to 2,147,483,647 so anything outside that range an integer type simply cannot store it. Lets look at this line of code:

As you can probably figure the answer is -4,000,000,000 but that is outside the range of integer. So one would expect to get an error but instead Java gives the answer 294,967,296. This is very bad in that if you are doing math related things you would get an answer and might unknowingly use the wrong answer thinking it was correct. This also gives us a difficult time when debugging in cases where the input value is unknown and this unwanted behavior is only present in certain inputs. Your program would compile fine, and maybe run fine most of the time but every so often it will give you the wrong answer and nothing to indicate that it did so. After a few tests I figured out the behavior of what Java does in these situations. If the number is outside the range of integer Java will wrap around to the other end of the range and continue the arithmetic from there. I figured this out by taking integer's lowest possible value (-2,147,483,648) and subtracting 1 from it and see where it lands. It lands on the integer's maximum value (2,147,483,647). So Java essentially doesn't underflow or overflows. Now I don't know why Java is designed like this but in this situation one would want some indication of when it underflows or overflows so we don't get wrong answers in our calculations. So in this respect this behavior is pretty bad. The same thing happens when we do 2,000,000,000 + 2,000,000,000. We know the answer is 4,000,000,000 but Java cant store that value in an int, it gives us an answer anyways (-294,967,296)..... How can adding two positive numbers result in a negative number... bad Java BAD! Go to your room!!!

    Now this next problem isn't really a problem and it isn't only Java but several other programming languages as well like C#. The problem here is with the modulus operator. With all positive numbers as parameters it behaves as it should but when you add a negative number into the mix things become off. This is because some languages' modulus and clock arithmetic behave differently. And thus in cases like:

Java and C# gives the answer -1 while clock arithmetic and several other programming languages will give you 2. If you think about it 2 makes sense in that you actually have something left over and that it shows that the number is 2 MORE than a multiple of 3 (-10 is 2 more than -12). It doesn't really make sense to have a negative amount left over, but then again depending on your definition here -1 also makes sense in that it shows that -10 is 1 LESS than a multiple of 3 (-10 is 1 less than -9).
So if you are doing modulus keep the scenario of negative numbers in mind and that remainder and modulus are not always the same thing or defined the same.

    So enough with ints what other variables are there.
First we can look at a boolean. A boolean stores one of 2 states. You can think of it as being one bit (although it does NOT take up only 1 bit in memory). Booleans in Java do not store numeric values it seems and only "true" or "false" states. Now lets take a look at a byte. A byte is a representation of 8 bits in memory. A byte is typically the smallest unit of data after a bit that people use. In Java it can store the values between (inclusive) -128 to 127 with a maximum of 256 possible states. As you can see this has the same fault as int mentioned above. Even though technically it can represent values up to 255 (because 0 is a state you cannot store the value 256) starting from 0 it is wasted on negative numbers when negative numbers aren't needed. Furthermore byte data is usually thought of as being a value between 0 and 255 so again I don't know why Java is designed this way.
Next you might say what if we double the number of bits/bytes. Wouldn't that allow me to store a larger number? And yes you would, for a 16 bit/2 byte type it is usually called a short. This stored the inclusive range of -32,768 to 32,767. And then if you double that to 32 bits/4 bytes you get int which we have discussed above. Finally for whole numbers of primitive types we have long. A long is a 64 bit/8 byte type. It can store the inclusive range -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. Besides whole numbers we can also represent fractional numbers. For this we have the floating point types first of which is float. Float is a 32bit/4 byte variable. It stores the value in a specific format as the sign (whether positive or negative), the exponent (power at which to raise to), and the fractional part (value to use in calculating the original number). Now because these numbers use exponents to represent their values their range can be from a very small to very large but at a price. Precision/Accuracy is forsaken due to rounding errors when trying to store a number that is too specific (large number of decimal places). Float types can store values between 1.40129846432481707 * 10^-45 to 3.40282346638528860 * 10^38 (positive or negative) or about 7 digits. We can increase the precision and accuracy by doing what we did with the whole number types and that is to double the number of bits/bytes. In doubling the size of a typical float we then get a 64 bit/8 byte floating point number the double. Now this can store even larger/smaller numbers ranging between 4.94065645841246544 * 10^-324 to 1.79769313486231570 *10^308 (positive or negative) or about 15 digits. Finally there is the char type which is used to represent individual characters. Char has a maximum of 65536 states and can store the numeric values of between 0 and 65535. To get around the unsigned short problem you can do arithmetic with char types if needed but it becomes unclear for others when reading it even thought a character and a number its typically (because of the type name) thought of as characters.

    Lets move onto operators.
In Java there are a couple operators although I personally wished there were a couple more to make out lives easier but essentially we have the following:

Now there are others but these are basically what people will use mostly.

Wednesday, December 23, 2015


While working on my game I needed to be able to see how many different colors there were in an image. I figured there were online tools to do such an easy task but everywhere I looked it either was inaccurate or didn't do what I wanted. So I went out and made a small app which counts the different colors used in an image as well as displays how many times each color was used.


Usage: Drag image over application.

Source (VB.Net):

Saturday, December 5, 2015

Game Project

     For several months now I have been working on a project much different and much more interesting than any of my previous ones (in my opinion). It has been very challenging (probably because of the way I decided to do it) and presented many obstacles which I needed to over come. This project is essentially a game or more specifically a game engine (a very simple 2D game engine). I started this project about 2 to 3 years ago with the thought of making a Pokemon game just for friends and family to play. That project eventually saw a dark fate when I managed to mess up my computer and lost all my work regarding it. Jump forward a little bit and I have revived that project though it has been altered a bit. I changed it from GDI+ to DX. Got CPU usage from around 15 to 20 percent (8 threaded CPU) down to less than 1 (depending on configuration used). While I still do plan on making a Pokemon game for friends and family I have been working on a type of fighting game as that has presented me the most challenge. The Pokemon game will most likely be my second project relating to games and will most definitely recycle the work done on the fighting game. There are several other features and updates that I have presented since my initial version which was lost but I don't feel they are interesting nor important enough to mention.

     Typically because I do not know if this project will ever amount to anything (or ever completed) I refrained from posting this on here and instead posted updates on my Facebook but I have recently been kicked out and unable to use my Facebook account (because I refused to use my real name nor do I plan on giving it to them). To continue posting updates I will have to resort to posting on here.

     Updates will be posted in oldest last and latest first order. All updates will have a date attributed to them.

[System Tested]
CPU: Intel Core i7 2600K @3.411Ghz
RAM: 8GB DDR3 @ 1600Mhz
GPU: Nvidia GTX 680

[APR 22 2016]
Moving everything over to MonoGame. Will hopefully provide Windows and Linux versions.

[JAN 21 2016]
I have since made some addition/changes but haven't gotten around to posting until now. I have added a "ColorPalette Management System" and a "PixelData Management System" they are in place to eventually replace the current "Sprite Management System" but currently all three are present for testing and debugging. I have worked out how I want to go about storing game assets (graphics in particular and sounds). Sounds will be in AAC format as there are no royalties involved in the usage of AAC media (unlike MP3). Several other formats are supported but AAC is recommended for reasons stated. Graphics Assets will be stored in a custom format/scheme. The game will have "CPT" (Color Palette Table) files which represent the colors of a particular palette and then another format "PID" (Pixel Image Data) which contains the representation of each pixel in bytes. The images are restricted to an Indexed8 depth meaning each sprite can have up to 256 predefined colors (in the CPT file). The two formats are separate because some sprites may share the same palette in which case it makes sense to reuse a palette instead of making a redundant copy in memory. The idea came about when exploring the GIF animated image format. I added a SoftwareRenderOnly mode for whats it's worth. Finally I moved around some things to better organize the project and workflow.

[JAN 12 2016]
Fixed and optimized my XorUInteger and XorULong structures to use for the engine. They are attempts at cheat prevention (for the simpletons but I'm sure the pros will still get around it). It basically works as you would think the name implies. It XORs the value with a randomly generated token so that the exact value is never stored. It also comes with checks to make sure the token is valid and that the return value hasn't been tampered with.
Source XorUInteger:
Source XorULong:

[JAN 11 2016]
Added mouse tracking although it isn't complete. Will have to get mouse tracking to properly scale with the window (Right now it works properly when the window is it's native resolution but any smaller and the tracking goes whack).

[JAN 08 2016]
Added a bit to the audio manager. Its able to stop any instance of audio that has been played. During playback an Instance ID is returned and that ID is used to distinguish that audio instance from the rest. That same ID will be used to stop playback of that audio instance if that instance is still playing, if not nothing will happen. Instances start with ID 1, if an ID of 0 is obtained that means the audio instance failed to play (most likely due to missing audio from collection).

[JAN 06 2016]
Improved the fullscreen, now fullscreening from a maximized windowed to fullscreen works and unfullscreening goes back to maximized bordered if it was previously so. Maximizing from a normal boredered window also maximizes and unmaximizes back to a normal window. With the addition of the new GameTimer I found that resizing the window doesn't impact the game much and so I removed the bit where it blacks the screen and suspends the layout until resize has completed so now you can see the game being resized as you resize it. This also gives the plus effect that the game doesn't blacks out when you move the window around. I fixed a problem with the mouse cursor showing over the game when it was specified not to so not when you want to hide the mouse cursor it wont show up anymore. Deleted some unnecessary functions and cleaned up some variables.

[JAN 05 2016]
I implemented my new GameTimer which provides more accurate control over frame-rate which still provides the low CPU usage of the older GameTimer.
I added a third buffer to try and mitigate some stutter I see.
I also hope that this fixes the inconsistencies between FPS on Intel vs AMD machines but will need more testing.
Source for the new GameTimer can be found here:

OLD GameTimer ex:

NEW GameTimer ex:

[JAN 04 2016]
Game now knows when its in focus or not so to grab inputs or not. Changed a bit of the rendering logic so it doesn't have draw queues (was made irrelevant with the buffers but forgot to take it out).

[DEC 30 2015]
Implemented my sound system. I haven't done too much testing but I know that it works. Essentially it is just my previous sound engine code I made a while back. It can do multiple instances of sounds and so a bunch of sound effects going at once shouldn't be a problem. The loading method is similar to the loading method I use for loading graphic assets. What to work on next I wonder.

[DEC 26 2015]
In addition to scaling I have implemented full screen. Full screen is mapped to F11. I might change it to Alt-Enter sometime later.

[DEC 23 2015]
Messing around with different image formats again and I think I will settle for the old fashion GIF format (or more accurately some of its concepts). GIF has a maximum color palette of 256 colors and so each pixel only takes one byte to represent a color. With about 3000 character sprites loaded into memory I figure that will be about a little over 1GB of memory. Of course this is excluding other things like background and effects as well as sound and game logic but I think its much more manageable now memory-wise. I played a bit with vectors and while memory becomes no longer an issue with simple sprites the more complex ones (ones with many angles) seem to be about the same or in some cases worst (though sprites looked so crisp and sharp, its a shame I couldn't use them). I might still use vectors for some things (large but simple effects) but not sure yet, but surprisingly vectors are pretty resource hungry (because they have to be calculated each time where as with an image it only needs to be drawn I figure).

[DEC 22 2015]
After scaling was implemented I had to center the view port but doing so revealed that everything would render to the edges of the window. I went ahead and implemented a constraint on the view port effectively creating a letterbox effect that has the same aspect ratio as the render resolution.
Ex (16:9 ratio):

[DEC 21 2015]
Got to implement scaling so now changing the size of the window wont crop or letterbox anything, instead everything is scaled up/down relative to the window and internal rendering resolution.

[DEC 13 2015]
Finished/Fixed dead zone correction for EZPAD. Download and source updated below.
Changed a couple things in terms of graphics.
Found a weird behavior where a frame sometimes drew an image out of place and of unspecified size, fixed it by having 2 buffers instead of one (buffer isn't used here in the normal sense of back buffers).

[DEC 12 2015]
Decided to redo the XInput lib for ease of use, flexibility and usage more straight forward.
New one is called EZPAD, Download and source is provided below (VB.NET).
     Imports EZPAD
     Dim NewGamePad As New EZPAD(PLAYER.ONE)
Old XPadMonitor Source:

Sunday, October 18, 2015

Millisecond Timer

   So a while back I discovered that windows can't do microsecond accurate timers (at least not in a straight forward way). Windows is not real time operating system so events are triggered differently for different computers. There are ways like the MicroLib I found on the internet a while back but it is very resource hungry using up almost 100 percent of one of my cores. This is because it is essentially polling a stopwatch and seeing if the number of ticks is equal to or greater than the specified Tick which is calculated per computer. I have tried to modify it to be less resource hungry but my attempts failed. I recently found some code which utilizes the windows multimedia api to achieve a more accurate millisecond but it was only accurate down to the millisecond and cant achieve for example 16.7 milliseconds. I then thought hey I can put the two together. This millisecond timer can achieve closer to the specified millisecond like 16.7ms which is the duration of a frame in a 60FPS game. Now this isn't perfect but I'd think this is as good as it gets (for me its exactly what I needed). If there are better methods/alternatives please comment or if you have any suggestions or improvements.

[UPDATE JAN 05 2016]
I got around to redoing my GameTimer. The previous one was very inaccurate. For example I would specify 240FPS but it would give me ~230FPS and when specifying some other rates it is also all over the place. This new one addresses those as well as keeping all the features of the old one.

Source (VB.NET):

Sunday, September 6, 2015

Transparent JPG

[Update 7] TransparentJPG.Dll quality default is now 80 and smoothing default is now 20. Progressive mode for the JpegEncoder is enabled potentially resulting in smaller file sizes. TransparentJPG has an added parameter for subsampling detail level. Options are 0 low (Default), 1 (medium), 2 (High). 2TJPG.exe has the added parameter as well.

[Revert 1] Changed back to using the LibJpeg.Dll. Smoothing is available again. Updated source below as well as the download and Latest Builds. The source for the version that is not reliant on LibJpeg.Dll will still be provided for reference.

[UPDATE 6] Removed the dependency for the LibJpeg.Dll which means that smoothing feature which helped save some space is now gone :( . I did so because I was given a 6Kx4K image to convert to TJPG and the converter (2TJPG.exe) kept crashing. I debugged it and found that LibJpeg was the problem. I am guessing that lib doesn't support images with such large resolutions? Either way I had to address the issue so I went and resorted to using Microsoft's built in encoder. It is slightly faster now due to not implementing the smoothing feature but file sizes will be slightly larger. The below has also been updated and contains (2TJPG.exe, TJPGviewer.exe, TransparentJPG.Dll). So essentially encoding will be different but decoding stays the same. The converter has also been updated in that it no longer supports the "Smoothing" parameter.

[UPDATE 5] Changed the color of the background squares of TJPGviewer.exe to a lighter shade(Grey) as well as made them 3x3 instead of 4x4 making them look less obtrusive.

[UPDATE 4] Optimized the code for saving TJPGs as well as removed all dependencies to LockBitmap.Dll(Removed from package). Also removed the CType to Byte() since it seemed redundant to the Decode method. Also provided SRC to TransparentJPG.DLL below.

[UPDATE 3] Changed the default values for conversion tool to quality=75 and smoothing=25. Also added a Decode method in TransparentJPG.Dll to get the pixel data, width and height of TJPG file. Also cleaned up the LoadTJPG function so that it doesn't rely on the LockBitmap.Dll though other things still need it, I will get to them soon.

[UPDATE 2] Fixed an issue with the converter (2TJPG.exe) where it would error and crash when given file paths that are valid and saying they aren't. Fixed version is provided in the "Latest Builds" link below.

[UPDATE 1] Added averaging when applying the mask to make the other bits of the alpha "useful" as well as provide a bit of compensation for rounding errors that jpeg compression might have. This has no impact on the encoding and only the decoding so file sizes are not affected though there is technically an impact on the resulting image visually it isn't noticeable and so negligible.
Moved all newer builds to a new location so people can grab this independent of the package I provided below:
Latest Builds:

     While working on my game I needed a way to import images and in my game people can share these images among each other via P2P. These images are almost always going to be grouped with tens if not hundreds, if not thousands of other images so I needed to pick an image file that is small in size. My next requirement was that the images needed to have transparency as a capability. Jpeg while small in size isn't capable of transparency. PNG has transparency but is much larger in size due to it being a lossless format. Another requirement was it needed to be compatible, I needed to work with an already existing format that most computers already know how to use so it wouldn't add time and complexity over compatibility. There exists much better solutions today but they are all either proprietary or there are no libs for them in use for .net which I need.

     I first thought hey I'll just take the pixel data from an image and limit it to 6 bits per channel then compress the whole thing which gave rise to a format I called TZI. While TZI proved to be a more acceptable format to my game than PNG I thought why don't I try a lossy attempt.

     I looked at Jpeg and I already knew the complexity behind its compression so I wasn't going to mess with the inner workings of Jpeg. Instead I thought of a hack about way to add transparency as another level on top of Jpeg. I did this by simply creating a mask via the images Alpha channel. I then removed all transparency from the image. The mask was then appended under the original image (with the alpha turned off). What you get then is an image with no transparency on top and a greyscale image of the Alpha channel on the bottom. I couldn't stop there, people randomly running into this image and viewing it as a typical Jpeg would be confused and the image shown isn't even in its intended form. And so I had to change its header so that people don't mix it with Jpeg files (even though this is essentially what this is). To reconstruct the original intended image I made an application which views the TransparentJPG files.

     The image is loaded in memory. The alpha mask is applied and then the image is essentially cropped to half its height. There is actually more detailed aspects going on behind the scenes and the workings is a bit different from how I explained it but I figure just a gist of how it works is good enough and easier to understand.

Code (VB.Net):

Code-not LibJpeg.Dll reliant (VB.Net):

Converter and Viewer Tools:


Now because of the added height as well as the transparency bit the images will never be smaller than their original non-transparent JPG version (with the same quality etc).

    Here is an exact representation of an image with its header unchanged after the mask has been generated:

    Intended Image:

    Here is another example of how the images are encoded without the header change:

    Intended Image:

Friday, August 14, 2015


[UPDATE 3] Removed the unnecessary function ClearBits() and its calls to result in >3x performance increase on adding bits (benchmark times updated).

[UPDATE 2] Changed out arithmetic operators for bit-wise operators as well as omitting the use of Math.Floor for a result of ~20 percent speed increase in setting bits (benchmark times updated).

[UPDATE 1] Fixed a bug where the 8th bit added is always set to True(1).

I previously made a class called TBitArray with the purpose of storing individual bits. At the time I didn't know that .Net already had a BitArray class which I could use so I made mine. I then thought well if I have an array I might as well make a list version as well. At the time I never got around to it. Then time passed and I started work on my encoding schemes. I needed to store bits that would resize as needed but I was lazy and instead stored each bit as a byte (yeah waste of space I know). This time I am working on a potential image format for my game. For this format everything is encoded and decode by bits and so again I needed something that would resize as needed. This time though I actually got to working on it. I know that one can resize the BitArray that is built into .Net but I did some benchmarks and well its VERY slow. So with speed and dynamic size in mind I set out to create a BitList class to make my life easier for this and potentially future projects. And I am sharing it here for those who may want to use it. I will provide the benchmarks first to show the difference. If anyone has any suggestions please leave a comment :)

As you can see BitList is much faster at adding bits when size is unknown and where size needs to be changed dynamically.
If you know exactly the number of bits needed please use the built in BitArray instead as you can see it is much faster at setting bits.

This class was made for my purpose of adding bits and not the constant manipulation of bits in memory. So if you need to constantly add bits this might be for you. The bit manipulation implemented is only for light use as it is slower than bit manipulation with BitArray, though slow it is still reasonably fast. Just use it where appropriate is all I'm saying.

Note: This class only implements the functionality that I myself needed, it does not provide other functionality that a typical List(Of T) has. If you need them you may implement them yourself or I might add this when my needs apply. I guess this is much closer the a queue then a list but too lazy to rename it lol. I could have also used a BitArray to store the lookup table but anyone who wants to do that is free to.

Code (VB.Net):

Saturday, August 8, 2015 with keyboard support

So my little brother's friend found this 'mod' for that allows one to play the game via the keyboard but he didn't know how to use it. I took a look and it linked to some survey site which automatically if anyone knew anything about these things online and running into surveys etc... its all crap. So instead I decided to make an app that allows one to play with keyboard.


Info: made in .NET via VB. Uses E, S, D, F for movement, and R to enable/disable keyboard movement support (and shows/hides the mouse cursor).

Saturday, August 1, 2015

Cleaning up a Yamaha PSR-310 keyboard

So I recently got a used keyboard because I wanted to learn piano eventually. The one I got was very dirty and there were scratch marks, the keys were stiff as well as stuck, and the lowest C key didn't even work. I thought hey lets clean this up and thus started my overnight project (started at ~12:30AM).

First I had to disassemble the keyboard of course:

The thing was nasty inside:

Is that semen?

There was a bit of rust

So I got to sanding

The membrane was nasty as all hell, cleaned it with a dirty shirt, I think it has to go in the trash now

SOOOO much better :)

Rubber pads are nice and clean as well

Now to get to the keys

As you can see its pretty nasty on the outside too

Black keys are cleaned though still wet

Put the membrane back into the keypad frame

Placed the rubber pads on aswell

Now to address the original issue, Time for some lube

Lubed highest key and first key pair and assembled

Onto the second




Finally placed the key assembly back into the keyboard enclosure

Consequently the lowest C key now works AWESOME lol. Completed ~5:30 AM.

I used soap, bleach, and alcohol as cleaning solutions.
Cotton swabs for fine cleaning and lubricating.
Regret using toilet paper to clean, as well as using my dirty shirt.

Thursday, May 28, 2015

[Release] JSXviewer 0.5b source

I don't know if I will ever get back to this but I decided that the program should be open a while back. It didn't really get that much attention and no one looked into improving/changing/rewriting/finishing/etc it. So I will post here in case people didn't know. The src is in and isn't commented as much as it should but here it is, do with it what you will lol.
Please if you have any suggestions or other feedback let me know in the comments.

Tuesday, April 21, 2015

[Planned] XwitchBot3

    Welp I haven't worked on/updated XwitchBot2 in forever but I do want to get back to it but I don't think anyone is using the plugin system to the extent I wanted, I don't think anyone besides myself has made any plugins for it. I don't plan on removing the plugin system or anything like that, if anything I want to expand it even more. I will be planning on potentially a third version of XwitchBot, one that is hopefully more polished then XwitchBot2. Now this is planned, whether or not it will ever be completed is another matter completely as I will be working on this in private if/when I am. I just wanted to say that I have been thinking about how XwitchBot's development has been, or lack thereof and wanted to stop neglecting it lol.

    Of course every reversion of XwitchBot has had a GUI overhaul and I think XwitchBot3 will be no different in that it too will most likely get a GUI overhaul. I'm picturing something similar to steam's UI but its not concrete yet a concept. There are other features that I think will benefit XwitchBot like possibly implementing some form of scripting. I don't know if I will be using an already available language or Frankenstein my own if I do plan on implementing one, of course implementing an existing one sounds much more practical.

    While this will be a reversion many aspects will be reused from XwitchBot2 just like how many aspects of XwitchBot2 were from XwitchBot. Things like I said the plugin system are there to stay, and the TwitchAPI from XwitchBot2 will still play a big part. I don't know what this blog post will ultimately amount to if anything but it's just ideas that I have been thinking about and of course if this comes to fruition XwitchBot3 is free, and will always be free like its always been.

UPDATE 8: Just another screenshot after fixing some UI alignments with some actual channels

UPDATE 7: Worked on the UI for each channel, some things are working now, still need to move several things around and implement others. Added donate button and home button that will eventually link to XwitchBot3 page but here is what it looks like so far:

UPDATE 6: Redoing the UI. It will be similar to XwitchBot2 versions but with adjustments to accommodate the new features. It isn't complete but much has been done. Currently it can connect to Twitch, Login using OAuth, Join channels. It cannot display messages or send them yet.

UPDATE 5: Got multichannel fully implemented and working, it also keeps track of the users in each channel. Added several MessageTypes for ease of plugin creation. Added proper parsing of initial twitch userlist (irc 353) and also added a type to tell the bot when the userlist ends (irc 366). Bot can only see registered users in the chat so the number of people shown on the bot vs the number of people on the stream will differ. Added MessageType (irc 421) for unknown commands so the bot notifies the user of any mishaps. Added parsing for originating channel of a message because the bot now has to keep track of messages from multiple channels. I will be implementing the ACTION aka /me MessageType and also the Points system as well as the AccessLevel system (differently levels have permissions to do different things). I also plan on slightly modifying the UI but only slightly since V2 UI is good enough.

UPDATE 4: Worked a bit on the YoutubeRequest class again. Added a bit more of the iframe API, I don't think ill add anymore of the API. Added a check for songs that don't start. Once a song is set to be played, and failed to start playing within 5 seconds the song will be skipped and the next song will be set to play. The duration to wait and see if the song starts can be changed (in milliseconds) in the constructor. There are 2 added events to the YoutubeRequest class. A polling event which presents the player's status such as song duration in seconds, the percentage of the song thats been buffered, the current position in seconds of the song, if the video is muted, and the current song's volume, as well as the current players state (is it playing, paused, etc), this polling is triggered every half second.

UPDATE 3: Well I will be changing some changes from UPDATE 2. In UPDATE 2 I planned on having the IRCclient be able to have multiple instances meaning each IRCclient establishes its own connection to the twitch server. I originally thought that because twitch's IRC is broken it couldn't join different channels through just one connection. From the website each tab I'd imagine creates a new connection and so I went to do it that way. Today though I remember a few of my friends who use HexChat to connect to twitch chat and I think I remembered them saying they can connect to different channels and so I went and tested. I can indeed connect to different and multiple channels. So I will be changing the bot in that respect. There will only be one instance of the IRC client again but It will be modified to handle multiple channels. I have also improved the message buffers and made the Message Structure simpler. The UserList is now moved inside of the IRCclient Class (it cant manage multiple channels yet, but will get to it). Because the PONG reply to PINGs is always the same (PONG I made it so that it replies only that and removed all parsing of the PING messages. When a PING is received a predefined byte array containing (PONG will be sent. Added more exception handling. Date/Time of messages in timestamps are set when the messages are received compared to previously where the Date/Time were set when the message was displayed in the chat. Sent message structure also has Date/Time now instead of setting the time when the message is displayed (this might be more accurate but timestamps might be out of order when displayed, I might change it back to how it was depending on how it turns out).

UPDATE 2: Reworking the core of the bot today. I made the IRCclient for the bot more robust. Put the message formatter (made because twitch's IRC protocol is broke as all hell) inside of the IRCclient class so that each instance of the IRCclient has its own formatter. Put the received message buffer and sending message buffers inside of the IRCclient class so that each IRCclient instance has its own buffers for the ability for multiple instances of an IRCclient (for multiple connections ex: connecting to multiple channels). Each IRCclient instance will have their own configuration (Server, Port, Channel, Nick, OAuth, etc). UserList parsing will also be available to each IRCclient instance so that it doesn't bunch users from all channels. Going to be moving the IRCclient class to Core class so plugins can access the IRCclient class (instead of making their own, which is a waste of time). Added PONG priority which will hold off on sending normal message so that PINGs are replied with PONGs sooner than later. Will be making a base class for the plugins interface so instead of implementing the XBPlgn interface, you inherit the XBextension class (you can still implement the interface if you want). Will be adding a database to the core of XwitchBot to keep records of things for the bot and for plugins as well (if needed). There will only be one instance of the database so that there is no conflicting records between plugins and the bot itself.

UPDATE 1: Worked on YouTubeRequest. Made a new class that implements more of the youtube player iframe API. It can play, pause, stop, seek, set volume, get duration and get the buffered percentage. I plan on reworking the plugin interface, and move the plugin system out of the bot and into the points system I will be implementing. The flow looks like this:
That way people can decide which plugins require points to use without programming each plugin to do so. I do plan on a UI overhaul but haven't yet thought of anything concrete.

Tuesday, March 10, 2015

Quick and Dirty .Net BigDecimal Implementation

[UPDATE 8] Added Conversion, Constructors, Comparisons, Operations for types Short, UShort, Byte, SByte.

[UPDATE 7] Added Ceiling, Floor, Truncate functions as well as fixed the Mod function. Added Ctype to/from byte arrays.
[TODO 3] Implement a BigDecimal rounding function that can round to a specified decimal place.

[UPDATE 6] Added a Random function which returns a random BigDecimal number with the specified number of significant digits.
[TODO 2] Fix modulus of negative numbers.

[UPDATE 5] Fixed constructors for Decimal, Double, and Single as arguments.

[UPDATE 4] Providing the new source code below.

[UPDATE 3] I rewrote the entire thing and improved the speed by ~5x to 10x. Removed all string manipulation hacks for calculations and added several other things for ease of use in code. I compiled it to a dll for ease of use.
Reference the BigDecimal.Dll,
     "Import TizzyT"
     Optionally you can also "Import TizzyT.BigDecimal"
     Dim bigNumber as BigDecimal = "51316561513854163416165416163163165613.1473415424496255785965457458965348754854856"
     Dim bigNumber as New BigDecimal("51316561513854163416165416163163165613.1473415424496255785965457458965348754854856")
The constructors accepts these types as the parameter:
String, BigInteger, Decimal, Double, Integer, Long, Single, UInteger, ULong.
Supported Operators: /, *, -, +, ^, Mod, =, <, >, <=, >=, <>
There are no BitWise operators.

[TODO 1] Add e constant calculation function and Phi calculation function. Add pre-calculated values to the first 65535 digits for Pi and e (and other constants in the future) for fast lookup and only calculating when needed. Fix potential rounding issue in the divide function. Support parsing and simple calculations with imaginary numbers. Raising to decimal powers.

[UPDATE 2] Added Pi function which (calculates Pi to the specified decimal place).

[UPDATE 1] Added square root function (calculates the square root to a specified decimal place).

    Now many of us I'm sure have gone to Wolfram Alpha and have done some calculations and get very precise answers. I thought why cant I just make a calculator that runs on the computer instead of relying on a website. The problem here is that I typically write in .Net and as far as I know in .Net there isn't yet a BigDecimal implementation though I hear something called Rational Number will be in the future (correct me if I'm wrong). .Net as of 4.5 does include BigInteger though and I figured "hey I can surely manipulate that to do decimals". So by playing with powers of 10 and some string manipulation I threw together this quick and dirty BigDecimal implementation. It does most of the basic arithmetic operations (add, subtract, multiply, divide) and also includes modulus and a limited power operator (only decimals to integer powers allowed).
It also has most of the basic comparison operators (=,<>,>,<,>=,<=).

     I didn't implement a way to do powers (exponents) of decimal numbers to decimal numbers as I don't know of any way to do arithmetic that are to the power of a decimal number. This is one of many things Wolfram Alpha and other tools are still useful for. I did however add a power operator where you can raise a decimal number to an integer power. Again this was a quick and dirty implementation by use of an already existing BigInteger and some string manipulation so this is more of a workaround then a full and proper implementation. With all that said this works as it is intended and I just thought I'd share this for those who want to have such capabilities and/or not want to make their own or use one that others have made (for what ever reason). Below is the source in, feel free to critique it constructively or even suggest improvements/additions/corrections/other changes (they are always welcome) in the comments, even link to other/better implementations for others to learn from (including myself lol).

     Here is a brief and simplified explanation of how the operators work (take note of the number of digits after the decimal places, trailing zeros after the decimal are omitted).
How Addition is done:
     ex: 2.5 + 3.56
     250 + 356 = 606
     606 * 10^-2 = 6.06
How Subtraction is done:
     ex: 3.56 - 2.5
     356 - 250 = 106
     106 * 10^-2 = 1.06
How Mulitplication is done:
     ex: 1.23 * 2.34
     123 * 234 = 28782
     28782 * 10^-4 = 2.8782
How Division is done:
     ex: 2.75 / 1.23
     27500 / 123 = 223.5772...
     223.5772... * 10^-2 = 2.235772...
How Modulus is done:
     ex: 81.913 mod 1.89
     81913 mod 1890 = 643
     643 * 10^-3 = 0.643
How Powers is done:
     ex: 3.86 ^ 3
     386 ^ 3 = 57512456
     57512456 * 10^(-2 * 3) = 57.512456

Here is an example of what this BigDecimal can do:

Wolfram Alpha would show:

This will give:

New Source:

Old Source:

Free for non commercial use. All changes to source must be provide here.