Notes on codes, projects and everything
We were asked to develop a program that demonstrate Artificial Intelligence and apply what we had learned in class into the program. Then we came out with an idea to develop a program that is able to do tarot reading. At first the program did not have a GUI and is operated through Swi-Prolog interpreter but in the end we included a GUI-frontend for the program using XPCE.
First the program will require 3 random numbers from the user, then a random number will be generated as the seed. Then the card will be “shuffled” (in fact, we did some calculations to the user provided random numbers) and then determine the orientation of the card (normal and reversed). Then, we use the computed number to pick a tarot card and get the reading based on the orientation.
To shuffle the cards, we use a random number and place the random number into the formula such that $$c=x^y\text{ mod }23$$ where c is the corresponding card number, x is the user provided number and y is the system generated random number. Then the orientation of the card is determine by calculating the mod 2 of the random number.
To implement simple search strategy, we used a hash function to divide the total of 22 major arcana cards into 5 groups. Each group will have one individual database file storing the card characteristics and reading. Then, depending on the calculated number, the system will choose to query which database file to decrease the inclusion of database files. We may not be able to observe the performance enhancement as we only have 5 database files but it should be more obvious for system with more database files.
I am the developer for the GUI front-end. At first we planned to write the GUI using other languages/platforms but because of the time constraint we decided to give up on GUI front-end. However, I managed to pick up basic XPCE GUI construction just in time and made a GUI for the program. However, the GUI is not very friendly and is not able to display images. Because XPCE is a multi-platform supported toolkit therefore the appearance of the GUI is consistent in various supported operating system.
The program is reading input through prolog interpreter.
The program displays the result after computing the input.
The program is reading input through GUI
The program displays the result through the GUI
Often times one would have to write code to evaluate logical statements. For example, given statement p and q, what is p implies q? As there’s no operator for implication in PHP, one would have to rewrite the statement that consists only in NOT (!
), AND (&&
) and OR (||
) operators. When there are a huge load of these statements, code can be difficult to read.
I have been following this excellent guide written by Benjamin Thomas to set up my virtual machine for development purpose. However, when I am starting to configure a Ubuntu Quantal alpha machine, parts of the guide became inapplicable. Hence, this post is written as a small revision to the previously mentioned guide.
Not sure about the others, but the obsession to my coding tools is probably more than I would admit. I have just managed to do a dirty quick hack to manage my VIM configuration settings. While I am sure there are other people doing this, I would like to show my reinvented wheels.
This is the formal draft of my statistical analysis report for the social audit project previously mentioned here. As the project is public by nature, I am cross-posting here for own reference.
(more…)I often struggle to get my Javascript code organized, and have tried numerous ways to do so. I have tried putting relevant code into classes and instantiate as needed, then abuse jQuery’s data()
method to store everything (from scalar values to functions and callbacks). Recently, after knowing (briefly) how a jQuery plugin should be written, it does greatly simplify my code.