Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views


Sign in to follow this  


It appears that C++ Templatemeta programming has got into my brain more than I thought.

We were learning more Prolog stuffs today at college and one of the tasks was to add all the even numbers leading up to a number (so for 8 it would be 8,6,4,2 and for 9 it would be the same).

So, my first function took the number and a var for the result and then I wrote two extra functions which had an extra paramter which indicated if it was odd or even.

addEven(N,X):- Z is N mod 2, addEven(N,X,Z).
addEven(N,X,0):- Y is N-2, addEven(Y,X2,0), X is Y + X2.
addEven(N,X,1):- Y is N-1, addEven(Y,X2).
(I think it was something like that I did...)

yay Prolog!

My lecture went another way, which I didn't note down but he had an 'even' function which basically did what I was doing in the first rule. God knows whos was better as I never got him to look at mine.. I'll grab his code at some point and compare I think...

All in all I'm getting along fine with Prolog, the biggest problem I'm having is having to think in a recursive manner, when C++ coding I tend to favor loops over recursion so when placed into a language with only recursion my brain kinda looks at it funny... it's a matter of practise I guess.

I infact had to bail on a problem in class today because I was too tired, I'll attack it again later (I've had sleep since then) as I refuse to be beaten by a stupid programming problem...

In other news; the assignment for the gfx module is do something in 2D... I've decided on a 2d side scrolling shoot 'em up because it'll allow for plenty of 2D things...

The downside?
Has to be in Java.
To make up for this I intend on adding many Cat based pictures to it for random head breaking reasons... which should at least amuse me [grin]

Assumning it's any good I'll pimp it here post-results...

Right, I'm due down the pub soon... guess I should get ready to leave..
Sign in to follow this  

1 Comment

Recommended Comments

Prolog is fun to play around with. I had a Nine Man Morris game written in Prolog a few years back for an AI class I was tutoring, but I think I've lost the code. It's also easy and fun to code text adventures in Prolog too.

Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!