Quantum Programming?

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Post Reply
Alpha Omega
Posts: 288
Joined: Wed Oct 29, 2008 12:07 pm

Quantum Programming?

Post by Alpha Omega »

Hello everyone. I had a realization today after doing some pondering on AI. Has anyone tried using quantum theory in there programming? What I mean by this is writing code where you find all solutions to a given event and then save every solution to a specific text file. When you need the data just read the file instead of recalculating it. For example...

Code: Select all


#include <iostream>
#include <fstream>
using namespace std;

int main()
{
    int number=0;
    int identity =0;
    fstream fin;
    fin.open("brains.txt");
    if (fin >> number)
    identity = 1;
    else
    identity = 0;
    if (!identity)
    {

        for(int i = 0;i<1000000;i=i+1)
        {
            for(int j = 0;j<10000;j++)
            {
                number +=i;
            }
        }
        cout << number;
    }
    else
    {
        cout << number;
    }
}


This way you only need to do the calculation once. Could this be overloaded and used in every aspect of programming? If you are trying to move a box first calculate every possible situation between the box and the environment and save the results. Then when the user moves the box all solutions have already been found so it should run very fast.

Anyone think this could work?
Dorth
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Post by Dorth »

You do realise IO is far more costy than any basic operations?
Alpha Omega
Posts: 288
Joined: Wed Oct 29, 2008 12:07 pm

Post by Alpha Omega »

Dorth wrote:You do realise IO is far more costy than any basic operations?
Yes I know but I measured the difference in a test application. Multiplying 3*3 and reading the result of 9 out of a file were close. Obviously I wouldn't use this for basic operations, however you could use it for large segments of code that take longer than a basic operation. In the example counting to 1 million, ten thousand times takes roughly 45 sec on my comp however reading the file only took .015 sec.
jpoag
Posts: 25
Joined: Mon Aug 10, 2009 1:00 am

Post by jpoag »

Yeah, Quantum theory isn't the word you are looking for...

In computer science, we have a technique called Memoization (NOT memorization).

http://en.wikipedia.org/wiki/Memoization

Lookup tables are quite popular too. It's pretty common to see sine and cosine tables saved as textures. You can precompute any problem space and store the values for reference. (linearly interpolated)

Now, you'll run into the memory/speed issue. Assuming that a lookup in a table is faster than the given operation (not always the case, see 'Page thrashing' 2nd paragraph of the Overview section) then there is a direct trade off in memory for speed. Precomputing the problem space could exhaust the memory of the machine.

Now, this isn't to say that there isn't a place for precomputing, or offline rendering. Back in the day, Quake Maps had to have a BSP tree generated and light maps precomputed. This process took a couple hours (at least on my old 500mhz machine). Now-a-days this is done load time! A lot of lighting is done in real-time!

Precomputing AI decision trees isn't a bad idea. In fact, it's easier to precompute the search space and compose it into a tree for faster searching/navigation.

Now, exhausting the search space for moving a box (I'm thinking physics simulation) probably wouldn't be my first choice for a lookup table.

I have a game that uses natural cubic splines, which are great for approximating complex curves (think Zuma). However, the acceleration of the curve (2nd derivative) is pretty erratic, especially at sharp curves. I needed to normalize the curve by stepping and substepping to a set of points exactly 1 pixel in distance apart. On my fastest machine, it takes 30 seconds to generate. So I rendered the curve offline and loaded the data into memory.
-James
Post Reply