Category Archives: Programming

Dynamic CSS based on weather

Raymond Camden wrote a great tutorial on loading style sheets dynamically based on the user’s current weather. He poked fun at himself and the idea a bit at the beginning of his post, but I think it’s honestly a terrifically fun idea. As it’s beginning to get a bit colder as we enter the holiday season, it would be very… cozy… to have a site recognize the weather and respond with some cool blues and whites!

Will I get around to implementing something like this? Probably not. But I find it pretty interesting anyways!

Parsing and Tiles Structures Complete

Excuse the bad art. They’re placeholders. I’m not an artist.
I finished the parser and data structures to hold terrain (ground, walls, ceiling, etc.) tiles. Of course, they will likely be changed over time to accommodate new types of tiles, because right now I only have one – grass. The point is that it works and that at this point it can go through the entire data structure of tiles during each update without any slowdown.
I’ll probably want to add a second tile type soon just to make sure parser and data structures can handle different types. I guess I should expect error and add in some error handling for when the data file has incorrect characters in it.
And then I’ll be on to gravity and, with it, collision detection for the ground.

Level Layout Parsing

I’ve been thinking that documenting my work on Mr. Bear’s Adventure might press me to work on it a little more. It’s a basic platformer (or it hopefully will be) that I’ve been attempting to make. The idea isn’t to make some fantastic game; rather, it’s to just make a platformer at all. The only way to get practice is to churn out some simple games.
I had already created some sprites and done character movement, excluding any kind of collision detection or gravity. So, I hadn’t done much of anything yet actually. When I returned to work on it, I started on the parser to read external data files containing the level layout. Along with it, I started working on the structures used to store the levels.


I’m bored in class again! I’m taking two other classes that I didn’t talk about last time – Game Development and an AI project course. Both ofthese classes are project courses, and both worry me.
In my AI project course, I’m working with gem, the Kubos, and Ethan. We’re creating AI algorithms to play the game of Battleships. I feel like we’re pretty behind. We’ve yet to combine code at all. I’ve been working on the actual algorthms, but until I get the file reader/writer and main game loop, I can’t really test my algorithms.

Game Development is worrying me too. Here at UCI I’m working with gem, Ethan, and a person I met in class named Tony. They’re all programmers. In addition, we’re working woth a group of artists from the Paguna College of Art and Design. Our planning has gone great. We know what we want to make. Art design is coming along well. I’ve been impressed with the concept art Ive seen so far, but we haven’t finalzed by designs yet. We’re meeting this Saturday for the first one to really discuss things.
We’re just getting started on the prgramming for it though. It’s due in about five weeks, which is not very far from now. By that time it needs to be playable, but we don’t really need it to be complete. It should have one level, a small selection of enemies, etc. After the class ends, I’d like to continue working on it. I know most of the artists feel the same way; I don’t know about the other prgrammers though.

C# Attributes, Using statement, and Properties

More adventures in C#!
There are a few new concepts I learned recently while working. As the title of this entry suggests, they are attributes, the using statement, and properties. While all three were new to me, they’re very logical (as one would expect with anything dealing with programming).
Attributes allow you to assign metadata to your code. An attribute goes directly before the data it describes. It’s encased in square brackets and is of the form Key(Value). For instance, if I want to describe who wrote a particular class and when, I could put // Peter Anargirou, 7/9/2008. However, that isn’t very structured. Instead I could put [Author(“Peter Anargirou”),Date(“7/9/2008”)] directly preceding the class declarations. Attributes can be programmatically referenced by the program in which they exist, making them very useful for code reflection.
The using statement is also very interesting. It’s of the format using ( object declarations here ) { …code…}. Anything declared in the using declaration is deallocated at the end of the using block. For example, you can open a file in the using declaration and not have to worry about closing it. When execution leaves the using block, the file is closed automatically. It’s similar to a try/catch/finally.
Lastly, properties are something new I recently discovered. They’re similar to accessor methods in other languages. Normally, if I have an int that I want to be able to access from outside the class it’s in, MyClass, I make it public. If I do that, then I might accidentally overwrite it when I that’s not what I intend to do. Also, there’s no way to check what I’m doing with it. For instance, I might not want it to store a value of 0, but with a public int, I have no way of enforcing that. Instead, I could make a private int and have accessor methods. I might have private int count, public int getCount(), and public void updateCount(int newCount). This is definitely the preferred way of doing things, but now when I want to retrieve the count from outside, I always have to say MyClass myClass = new MyClass(); int x = myClass.getCount();. To update the count, I have to use myClass.updateCount(42);. With properties, you can create accessor methods that invoke automatically while you treat the property like a public variable. For example, I now write

private int myCount;
public int count
get { return myCount; }
set { if ( value != 0) myCount = value; }

Now from outside I can simply write x = myClass.count to retrieve the value and myClass.count = 42 to update the value. Of course, it’s also checking that I’m not updating with 0. If I try to update with 0, it won’t actually update myCount. It’s clean and simple yet still provides the more complex checking that can be done with accessor methods. Very handy!

HTML Form Combo Box

I found an interesting article on how to create a Combo Box in DHTML. Form controls are definitely in need of the combo box, but I’m not so sure this does the job all that well.
A combo box is a drop down select list that can also allow the user to input his or her own strings. The author of the article builds one in DHTML by first placing a select list on the page and then placing a textbox on top of it using CSS. He then causes the dropdown list to make a Javascript function call, causing the textbox to update with the value of the list’s selection. It’s interesting in concept, but you can tell something strange is happening. Looking at the page, you can tell there’s a rendering error (in this case not an error) and that there are controls stacked on top of each other.

Getting Vertical Scroll Position in a Div to Persist Across Postbacks

I’ve been working on this for a little bit now, and it was surprisingly easy. I just didn’t know all of the syntax.
First, any element in a webpage that scrolls has a scrollTop attribute that’s equal to the number of pixels it has been scrolled. When it’s scrolled all the way to the top, scrollTop is zero.
To cause this to persist, you can store it in a hidden input.
<input type=”hidden” name=”whatever” id=”whatever” value=”default” runat=”server”>
Name and id should be equal, and making sure runat=”server” is present is important. Now this should persist automatically. The only other thing that’s needed is to store and restore the value. You can use an onscroll=”nameOfJavascriptFunctionThatStoresThePosition()” attribute in the div in question to call a function whenever the div is scrolled. Then in your Javascript section, set window.onload equal to whatever function is going to restore it. Parentheses aren’t needed at the end because you’re mapping onload to a function.
The last thing to remember is that in your storing and restoring functions, you can’t simply refer to the id of the hidden input because your codebehind might, and most likely will, change it. You’d have to use <%=idOfInput.ClientID%>. You can use document.getElementById(‘ blah ‘).value, where blah is that previous tag. To restore the value that value should be set into the div’s scrollTop (again, you can use document.getElementById(), but you won’t need to do ClientID stuff because the div’s not runat=”server”. To store the value, you just set the scrollTop into that hidden input using that same method. Pretty simple!
Of course, if you’re not concerned with a div but rather the whole document, you can do a similar thing using body’s scrollTop or just enable SmartNavigation if the page is being designed for InternetExplorer.


Back mid-quarter, we had to create the AI for a Kalah playing program. Jacobson then had them play against each other and ranked the results on the course website. Here’s how he did it, copied from his document.

Each player’s score is the sum, across all games played, of beans in the player’s pot at each game’s end. The higher your score, the better you did.
Each (non-disqualified) player played two games, one as top player and one as bottom player, against every other (non-disqualified) player. Players were disqualified for taking longer than 5 seconds to make a move, making an illegal move, throwing unchecked exceptions at run-time or compile-time errors. We did not disqualify a player whose program wrote to the screen, though technically we could have done so.

And here’s the results ordered by high score rather than player, and with the half or so disqualified scores removed, with mine bolded (and gem right under me). I didn’t care about the formatting, but notice our positions when ranked by score 🙂
Player Score Record as Bottom Record as Top
5700 2197 20- 1- 0 18- 3- 0
xxxx 2191 20- 1- 0 19- 2- 0
xxxx 2187 20- 1- 0 19- 2- 0
xxxx 2184 20- 1- 0 18- 3- 0
xxxx 1935 15- 6- 0 18- 3- 0
xxxx 1920 15- 6- 0 15- 6- 0
xxxx 1752 13- 8- 0 11- 9- 1
xxxx 1682 12- 9- 0 14- 7- 0
xxxx 1575 10- 10- 1 13- 8- 0
xxxx 1369 10- 11- 0 7- 12- 2
xxxx 1342 9- 11- 1 7- 14- 0
xxxx 1304 7- 14- 0 7- 14- 0
xxxx 1300 12- 8- 1 4- 17- 0
xxxx 1271 11- 10- 0 1- 19- 1
xxxx 1210 11- 10- 0 3- 17- 1
xxxx 1194 9- 12- 0 2- 19- 0
xxxx 1180 10- 11- 0 5- 16- 0
xxxx 1167 3- 17- 1 7- 13- 1
xxxx 1152 7- 14- 0 5- 16- 0
xxxx 1148 8- 12- 1 4- 17- 0
xxxx 1061 11- 9- 1 1- 20- 0
xxxx 943 4- 17- 0 1- 20- 0

Science Library Looks Like a Vagina

I heard that the Science Library looks like a vagina.
Anyways, I doubt if WebPageless will really come back anytime soon. I guess this is semi-permanent. Cox blocks all incoming ports entirely. It’s like my computer doesn’t exist on the Internet. In better news, Cox has at least made the speeds go up to normal DSL/cable speeds. I also tried using the AntWeb. To set that up, I had to learn how to VPN into the school. But after setting it up, I found that pages on it are only accessible to people on the UCI network.
I gave up the Start Menu and Explorer a long time ago (about a year now). But I had used Black Box menus or BBIcons. Well, I gave it all up in trade for Google Desktop Search. I works really well. I use it to launch all my applications and everything. Good program. Good organization, that Google. I loves them.
My Palm Tungsten C died completely today. The screen is totally fucked up. Like Chopsticks. That really sucks. I kinda depend on it. I’m gonna sync to my dad’s Palm to at least get my financing info off of it.
I got about a standard deviation above the mean on the CSE 21 midterm. Did well on both projects. My Kalah AI was the best in the class. The average on my CSE 31L midterm was 54%. I got 97%. I’ve aced all my 31L labs, and have done well in Classics. Turned in a concert report on Tuesday. It went well, I think.
Last weekend was cool. On Friday, gem and I went to LNP. I wore a robe for Halloween and got in early. I never had got in early before. Then we rented Chamber of Secrets and bought Harvest Moon: A Wonderful Life. Saturday we played video games basically. Then gem, Jon, Gabby, Andy and I went to see Nnenna Freelon at the Jazz Bakery in LA. I thought it was a pretty good show. Afterwards we came back to my apartment, drank, and watched the Grudge. Gabby was too scared to watch. She kept hiding. Patrick kept scaring her. It was great. Chris was too talkative during the movie. Andy was a bitch, and we’re never watching a movie that matters with him again. Sunday gem and I worked on our labs. Christine came over, but we didn’t really get to do much. That night, gem, Jon, Gabby, and I went to Knott’s Scary Farm. It was a lot of fun, except Jon and Gabby fought a bit. But Gabby got over her fear of the big rollercoasters – kind of. Anyways, she went on it. And we got on quickly because Jon used a wheelchair.
Harvest Moon: A Wonderful Life is a really fun game. I thought the chapters would suck, but they don’t really get in the way of playing.
I finished reading Starship Troopers again. It’s so much better now than when I read it in highschool or junior high. I love Heinlein. And I love that book. Totally awesome.
On Tuesday (I think) I hung out with gem, Allison, and Lauren. It was fun. Afterwards Lauren went home, and the three of us went to Denny’s to eat. Great fun! I love friends.
I hadn’t talked to Kalin in a long time, but I’m chatting with him now. Good ol’ AIM.
My mom’s birthday was the 1st, and Pete’s is the 3rd. Happy birthdays! gem and I went out to dinner with them tonight to an Italian restaurant. I had the rigotoni, and it was great.
gem’s making Gryffindor scarves for us for the Goblet of Fire release.
Tomorrow I have a history of jazz midterm at one. I feel so unprepared. It has nothing to do with computers or math. Ah! But I’ll probably do alright.

CSE 22 Project 5

Fucked up a little.
Correctness: 9
*) Your program is well done. It passed all the tests. The only thing is
that there are always more spaces than necessary in your output.
+) Good quality!
+) Naming and comments are proper.
+) Program is neat and clean
+) Program is well organized.
+) You way to handle the ArrayList of RightHandSide is good: to generate a
new class which is the super class of Variable and Terminal. But you can use
generable also.
+) Good you tell the user that the output is finished.
+) Good you also considered exceptions

CSE 22 Project 4

Correctness: 10
+) Very well done. program passed all the tests!
Style: 10
+) Nice interface, correct and clear.
+) All operations are done in a proper class, i.e. within the scope of the
corresponding class.
+) Proper comments and proper naming.
+) Program is well organized!

ICS 22 Project 4

Wow, that sucked. I turned it in at 11:58 and didn’t finish commenting. I had a lot of trouble interpreting the instructions. When time came down to, I just grabbed a working bundle of source and turned it in. I had multiple ones, and while some seemed better code-wise, all but one gave different outputs than that on the website.
The one I turned in first checked if customers should be added to the lines and if so, added them. Then, for each window it did the following checked if there was a customer at the window. If so, it processed him or her. If not, it would move someone from the line into the window. I don’t know if it was right or not.
I did, however, become happy with my clock. If I pass around an int to keep track of time, methods could change it. If I make a clock object with a private int to keep track of time, a public method to change the time, and a public method to retrieve the time, any method could still change the time. So, I made a Clock class with the field/methods described above. Then, I made a ClockView interface that was the same except didn’t have the method to change the time. In Simulation, I did the following:
Clock clock = new Clock();
ClockView clockView = clock;
Now, using the clock reference I could change the time. If I pass the clockView reference to other methods, they can view the time but not change it. Yay!
We’ll see how I actually do.

CSE 22 Project 3

Correctness: 10
+) Very well done! You have passed all the tests.
Style: 10
-) When you report a fatal error, it is better to give the line number at
the same time
+) Coding is very clear and well structured.
+) You have handled the execution loop very nicely by having a “keepRunning”
variable in the programState class.
+) Good you have proper comments to give enough information about the
+) Naming of classes, methods and variables is good.
+) Good you have all fields private.
+) Nice quality of coding.

Project 2

Correctness: 10
+) File is read in successfully!
+) Good you did error checking when user wants to add a voter with the same
SSN as one existing voter. It is the same with polling places.
+) Very well done! Program is correct and robust. I wasn’t able to crash
it or get it to misbehave.
Style: 10
-) It would be better if you print out the voters or polling places in a
nice format.Use the String.format()
+) Very nice user interface! But you can still improve it by giving user
information regarding whether or not his/her operation is successful.
Furthermore, if the list is empty, print something to tell the user about it
if he/she would like to list the voters or polling places.
+) Well structured. Good you broke the go() of VoteUI into several pieces
+) Good you have proper comments
+) Good you have all fields private
+) Good naming for methods/variables
*) A minor thing: I don’t think it is necessary to create a MenuExecution
class since the VoteUI is enough for dealing with command execution.
Furthermore, all the variables related to the operations are all stored in
the VoteUI, it is not necessary to pass all of them as parameters to the

Project 3

I think I finished project 3. I’ve never finished early before. Still need to add comments and such though. Maybe do some more testing just to make sure. Yay.
Now I gotta do math hw, reading and a critique by Thursday. And study for Friday’s midterm.

CSE 22 Project 2

Project 2 was pretty fun, but come Monday night, I was stumped. It turns out I was creating new iterators rather than passing around the same one. Then I realized that my linked lists were referenced in two classes, but they weren’t the same linked lists. I fixed everything and finished my commenting at 11:56. Had the whole thing uploaded by 11:57. Two minutes to spare. didn’t work though. Oh well… maybe I’ll do better next time.

CSE22 Project 1

Correctness: 9/10
-) You did not deal with negative wages.
-) Your “Please enter employee’s name:” appears twice when I would like to remove an employee.
+) Other parts are well done!
+) Your interface is friendly
+) Your format of ShowEmployee and DoWeeklyPayroll is nice
+) Naming is good
+) Good you have proper comments
+) Good structured. It is nice for you to break the operations for different commands into different methods.
+) Good you have all fields private