Nevon
September 21st, 2009, 01:42 PM
I need some help with a problem I've encountered in a semi-educational game that I'm making in Lua using Löve (http://love2d.org). The basic object of the game is to create as large a difference between two sums as possible, by positioning 6 given numbers in various places relative to 4 operators. To show you what I mean, here's a rough visualization:
http://i33.tinypic.com/igkpp0.png
The operators are all distributed randomly, and the user can then place the numbers freely in the colored boxes. The three numbers on the left (together with the two operators on the left) form one expression, and the ones on the right form another. Once all numbers have been placed, the two expressions should be evaluated to see if it creates the largest inequality possible.
So basically, this is the objective of the game:
num[1] operator[1] num[2] operator[2] num[3] = sum[1]
num[4] operator[3] num[5] operator[4] num[6] = sum[2]
if sum[1] > sum[2] then
difference = sum[1] - sum[2]
else
difference = sum[2] - sum[1]
end
if difference == LARGEST_POSSIBLE_DIFFERENCE then
print "Winner!"
end
To do this, I assume the program would have to evaluate all possible configurations of the numbers and find the largest one. If the player's configuration evaluates to that value, he or she has won.
What I don't know is how to evaluate all possible configurations, and as such, that is what I would very much appreciate it if you could help me with. :)
Thank you, and please let me know if you have any questions.
http://i33.tinypic.com/igkpp0.png
The operators are all distributed randomly, and the user can then place the numbers freely in the colored boxes. The three numbers on the left (together with the two operators on the left) form one expression, and the ones on the right form another. Once all numbers have been placed, the two expressions should be evaluated to see if it creates the largest inequality possible.
So basically, this is the objective of the game:
num[1] operator[1] num[2] operator[2] num[3] = sum[1]
num[4] operator[3] num[5] operator[4] num[6] = sum[2]
if sum[1] > sum[2] then
difference = sum[1] - sum[2]
else
difference = sum[2] - sum[1]
end
if difference == LARGEST_POSSIBLE_DIFFERENCE then
print "Winner!"
end
To do this, I assume the program would have to evaluate all possible configurations of the numbers and find the largest one. If the player's configuration evaluates to that value, he or she has won.
What I don't know is how to evaluate all possible configurations, and as such, that is what I would very much appreciate it if you could help me with. :)
Thank you, and please let me know if you have any questions.