Jump to content

  • Log In with Google      Sign In   
  • Create Account

alnite

Member Since 07 Nov 2002
Offline Last Active Yesterday, 10:21 AM

Posts I've Made

In Topic: Is there any reason to prefer procedural programming over OOP

21 June 2016 - 11:38 AM

Lots of great points here.  It really comes to what problem you are solving, and in order to be able to identify when to use what, you'd need experience.  Here's something that I came across not too long ago at work that I solved using procedural.

 

The problem that I was solving was related to caching:

1. Get value from cache

2. If not available in cache, get it from database

3. Then store the value from the database to the cache

 

In Ruby, you can pass an anonymous function to another function.  The function that receives this anonymous function may decide (or not) to invoke.  This is what the function roughly looks like:

 

def get_from_cache(key, &block)
  value = cache.get(key)
  return value if value
 
  value = block.call # call the anon function
  cache.set(key, value)
  return value
end

 

The function is simple enough.  Attempt to get value from cache, if found, return value immediately.  If cache doesn't have the key, invoke another function, and use that function's return value as the value for the key.

 

We can 'chain' this up, creating complex logic structure.  Examples:

 

# Get value from database and cache it
value = get_from_cache("foo") do
  get_from_database("foo")
end
 
# Get value from HTTP and cache it
value = get_from_cache("foo") do
  http("http://www.gamedev.net/posts?key=foo")
end
 
# Or multiple caching layers
value = get_from_cache("foo") do
  get_from_another_cache("foo") do
    get_from_database("foo") do
      http("http://www.gamedev.net/posts?key=foo")
    end
  end
end
 


In Topic: Non-duplicating pairs from a set

20 June 2016 - 12:45 PM

Need to be elaborated more.

 

If it's 6 pairs from a set of 13 numbers, then one of the world won't have any portal at a given time, correct?

 

Gen 0, your set will look like this: [0,1], [2,3], [4,5], [6,7], [8,9],[10,11]

World 12 does not have a portal open.

 

Then, what's the rule for picking the next set?  Is it sequential?  Does this mean that world 0 will always be given the priority to pick the next world?  And World 12 will be lonely until the 12th generation.

 

Example:

Gen 1, set looks like this: [0,2], [1,3], [4,6], [5,7], [8,10], [9, 11].  In which case 12 is lonely again.

Gen 2, set looks like this: [0,3], [1,2], [4,7], [5,6], [8,11], [9, 10].  In which case 12 is lonely again.

 

Edit:

 

Here's a proposal.  Use a queue/stack depending on what order you want them to be, and each world needs to keep track a list of worlds that it has had a portal open to until next reset.  Initially your queue is just the sequence of the world.

 

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]

 

Then, pop each world, if there's no world popped yet, keep this world 'open'.  Then pop the next world.  Attempt to link these two worlds together.  If two worlds have been linked together before, then it should fail the linking process, and you would have two worlds 'open'.  Repeat for the next world.  If pairing happens, "close"/"linked" both worlds.  Example:

 

Gen 0

 

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]

Pop #0.  Open: [0], Queue: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]

Pop #1.  Linked: [0, 1], Queue: [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]

Pop #2.  Linked: [0, 1], Open: [2], Queue: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12]

and so on.. until the last one

Pop #11. Linked: [0,1], [2,3], [4,5], [6,7], [8,9], [10,11]. Queue: [12]

 

Gen 1

Reinserts all world back to the queue:

 

Queue: [12, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]

Pop #12.  Open: [12], Queue: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]

Pop #0.  Linked: [12, 0], Queue: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]

Pop #1.  Linked: [12, 0], Open: [1], Queue: [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]

and so on.. until the last one

Pop #10. Linked: [12,0], [1,2], [3,4], [5,6], [7,8], [9,10]. Queue: [11]

 

Gen 2

Reinserts all world back to the queue:

 

Queue: [11, 12, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Pop #11.  Open: [11], Queue: [12, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Pop #12.  Linked: [11, 12], Queue: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Pop #0.  Linked: [11, 12], Open: [0], Queue: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Pop #1.  Linked: [11, 12], Open: [0], Open [1], Queue: [2, 3, 4, 5, 6, 7, 8, 9, 10]  // since [0,1] has been linked before

and so on.. until the last one

Pop #9. Linked: [11, 12], [0,2], [1,3], [4,6], [5,7], [8,10]. Queue: [9]

 

Gen 3

Queue: [9, 11, 12, 0, 2, 1, 3, 4, 6, 5, 7, 8, 10]

Final Order: [9, 11], [12, 2], [0, 3], [1, 4], [6, 8], [5, 10], [7]

 

 

You can get different linking order by playing around with different insertion order.  I am using the ordering of pairs, you can keep it sequential.  You can also use a stack instead of a queue.  I am using a queue so that the world that didn't get a portal open from previous generation would always get one at the next generation.

 

-- More edit:

 

Here's a list of all the portals:

 

Gen: 0
Queue Before: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
Linked: [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11]]
Queue After: [12]
Link History: {0=>[1], 1=>[0], 2=>[3], 3=>[2], 4=>[5], 5=>[4], 6=>[7], 7=>[6], 8=>[9], 9=>[8], 10=>[11], 11=>[10], 12=>[]}

Gen: 1
Queue Before: [12, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
Linked: [[12, 0], [1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]
Queue After: [11]
Link History: {0=>[1, 12], 1=>[0, 2], 2=>[3, 1], 3=>[2, 4], 4=>[5, 3], 5=>[4, 6], 6=>[7, 5], 7=>[6, 8], 8=>[9, 7], 9=>[8, 10], 10=>[11, 9], 11=>[10], 12=>[0]}

Gen: 2
Queue Before: [11, 12, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Linked: [[11, 12], [0, 2], [1, 3], [4, 6], [5, 7], [8, 10]]
Queue After: [9]
Link History: {0=>[1, 12, 2], 1=>[0, 2, 3], 2=>[3, 1, 0], 3=>[2, 4, 1], 4=>[5, 3, 6], 5=>[4, 6, 7], 6=>[7, 5, 4], 7=>[6, 8, 5], 8=>[9, 7, 10], 9=>[8, 10], 10=>[11, 9, 8], 11=>[10, 12], 12=>[0, 11]}

Gen: 3
Queue Before: [9, 11, 12, 0, 2, 1, 3, 4, 6, 5, 7, 8, 10]
Linked: [[9, 11], [12, 2], [0, 3], [1, 4], [6, 8], [5, 10]]
Queue After: [7]
Link History: {0=>[1, 12, 2, 3], 1=>[0, 2, 3, 4], 2=>[3, 1, 0, 12], 3=>[2, 4, 1, 0], 4=>[5, 3, 6, 1], 5=>[4, 6, 7, 10], 6=>[7, 5, 4, 8], 7=>[6, 8, 5], 8=>[9, 7, 10, 6], 9=>[8, 10, 11], 10=>[11, 9, 8, 5], 11=>[10, 12, 9], 12=>[0, 11, 2]}

Gen: 4
Queue Before: [7, 9, 11, 12, 2, 0, 3, 1, 4, 6, 8, 5, 10]
Linked: [[7, 9], [11, 2], [12, 3], [0, 4], [1, 6], [8, 5]]
Queue After: [10]
Link History: {0=>[1, 12, 2, 3, 4], 1=>[0, 2, 3, 4, 6], 2=>[3, 1, 0, 12, 11], 3=>[2, 4, 1, 0, 12], 4=>[5, 3, 6, 1, 0], 5=>[4, 6, 7, 10, 8], 6=>[7, 5, 4, 8, 1], 7=>[6, 8, 5, 9], 8=>[9, 7, 10, 6, 5], 9=>[8, 10, 11, 7], 10=>[11, 9, 8, 5], 11=>[10, 12, 9, 2], 12=>[0, 11, 2, 3]}

Gen: 5
Queue Before: [10, 7, 9, 11, 2, 12, 3, 0, 4, 1, 6, 8, 5]
Linked: [[10, 7], [9, 2], [11, 3], [12, 4], [0, 6], [1, 8]]
Queue After: [5]
Link History: {0=>[1, 12, 2, 3, 4, 6], 1=>[0, 2, 3, 4, 6, 8], 2=>[3, 1, 0, 12, 11, 9], 3=>[2, 4, 1, 0, 12, 11], 4=>[5, 3, 6, 1, 0, 12], 5=>[4, 6, 7, 10, 8], 6=>[7, 5, 4, 8, 1, 0], 7=>[6, 8, 5, 9, 10], 8=>[9, 7, 10, 6, 5, 1], 9=>[8, 10, 11, 7, 2], 10=>[11, 9, 8, 5, 7], 11=>[10, 12, 9, 2, 3], 12=>[0, 11, 2, 3, 4]}

Gen: 6
Queue Before: [5, 10, 7, 9, 2, 11, 3, 12, 4, 0, 6, 1, 8]
Linked: [[5, 9], [10, 2], [7, 11], [3, 6], [12, 1], [4, 8]]
Queue After: [0]
Link History: {0=>[1, 12, 2, 3, 4, 6], 1=>[0, 2, 3, 4, 6, 8, 12], 2=>[3, 1, 0, 12, 11, 9, 10], 3=>[2, 4, 1, 0, 12, 11, 6], 4=>[5, 3, 6, 1, 0, 12, 8], 5=>[4, 6, 7, 10, 8, 9], 6=>[7, 5, 4, 8, 1, 0, 3], 7=>[6, 8, 5, 9, 10, 11], 8=>[9, 7, 10, 6, 5, 1, 4], 9=>[8, 10, 11, 7, 2, 5], 10=>[11, 9, 8, 5, 7, 2], 11=>[10, 12, 9, 2, 3, 7], 12=>[0, 11, 2, 3, 4, 1]}

Gen: 7
Queue Before: [0, 5, 9, 10, 2, 7, 11, 3, 6, 12, 1, 4, 8]
Linked: [[0, 5], [2, 7], [9, 3], [10, 6], [11, 1], [12, 8]]
Queue After: [4]
Link History: {0=>[1, 12, 2, 3, 4, 6, 5], 1=>[0, 2, 3, 4, 6, 8, 12, 11], 2=>[3, 1, 0, 12, 11, 9, 10, 7], 3=>[2, 4, 1, 0, 12, 11, 6, 9], 4=>[5, 3, 6, 1, 0, 12, 8], 5=>[4, 6, 7, 10, 8, 9, 0], 6=>[7, 5, 4, 8, 1, 0, 3, 10], 7=>[6, 8, 5, 9, 10, 11, 2], 8=>[9, 7, 10, 6, 5, 1, 4, 12], 9=>[8, 10, 11, 7, 2, 5, 3], 10=>[11, 9, 8, 5, 7, 2, 6], 11=>[10, 12, 9, 2, 3, 7, 1], 12=>[0, 11, 2, 3, 4, 1, 8]}

Gen: 8
Queue Before: [4, 0, 5, 2, 7, 9, 3, 10, 6, 11, 1, 12, 8]
Linked: [[4, 2], [0, 7], [5, 3], [9, 6], [10, 1], [11, 8]]
Queue After: [12]
Link History: {0=>[1, 12, 2, 3, 4, 6, 5, 7], 1=>[0, 2, 3, 4, 6, 8, 12, 11, 10], 2=>[3, 1, 0, 12, 11, 9, 10, 7, 4], 3=>[2, 4, 1, 0, 12, 11, 6, 9, 5], 4=>[5, 3, 6, 1, 0, 12, 8, 2], 5=>[4, 6, 7, 10, 8, 9, 0, 3], 6=>[7, 5, 4, 8, 1, 0, 3, 10, 9], 7=>[6, 8, 5, 9, 10, 11, 2, 0], 8=>[9, 7, 10, 6, 5, 1, 4, 12, 11], 9=>[8, 10, 11, 7, 2, 5, 3, 6], 10=>[11, 9, 8, 5, 7, 2, 6, 1], 11=>[10, 12, 9, 2, 3, 7, 1, 8], 12=>[0, 11, 2, 3, 4, 1, 8]}

Gen: 9
Queue Before: [12, 4, 2, 0, 7, 5, 3, 9, 6, 10, 1, 11, 8]
Linked: [[12, 7], [2, 5], [4, 9], [0, 10], [6, 11], [3, 8]]
Queue After: [1]
Link History: {0=>[1, 12, 2, 3, 4, 6, 5, 7, 10], 1=>[0, 2, 3, 4, 6, 8, 12, 11, 10], 2=>[3, 1, 0, 12, 11, 9, 10, 7, 4, 5], 3=>[2, 4, 1, 0, 12, 11, 6, 9, 5, 8], 4=>[5, 3, 6, 1, 0, 12, 8, 2, 9], 5=>[4, 6, 7, 10, 8, 9, 0, 3, 2], 6=>[7, 5, 4, 8, 1, 0, 3, 10, 9, 11], 7=>[6, 8, 5, 9, 10, 11, 2, 0, 12], 8=>[9, 7, 10, 6, 5, 1, 4, 12, 11, 3], 9=>[8, 10, 11, 7, 2, 5, 3, 6, 4], 10=>[11, 9, 8, 5, 7, 2, 6, 1, 0], 11=>[10, 12, 9, 2, 3, 7, 1, 8, 6], 12=>[0, 11, 2, 3, 4, 1, 8, 7]}

Gen: 10
Queue Before: [1, 12, 7, 2, 5, 4, 9, 0, 10, 6, 11, 3, 8]
Linked: [[1, 7], [12, 5], [9, 0], [4, 10], [2, 6]]
Queue After: [11, 3, 8]
Link History: {0=>[1, 12, 2, 3, 4, 6, 5, 7, 10, 9], 1=>[0, 2, 3, 4, 6, 8, 12, 11, 10, 7], 2=>[3, 1, 0, 12, 11, 9, 10, 7, 4, 5, 6], 3=>[2, 4, 1, 0, 12, 11, 6, 9, 5, 8], 4=>[5, 3, 6, 1, 0, 12, 8, 2, 9, 10], 5=>[4, 6, 7, 10, 8, 9, 0, 3, 2, 12], 6=>[7, 5, 4, 8, 1, 0, 3, 10, 9, 11, 2], 7=>[6, 8, 5, 9, 10, 11, 2, 0, 12, 1], 8=>[9, 7, 10, 6, 5, 1, 4, 12, 11, 3], 9=>[8, 10, 11, 7, 2, 5, 3, 6, 4, 0], 10=>[11, 9, 8, 5, 7, 2, 6, 1, 0, 4], 11=>[10, 12, 9, 2, 3, 7, 1, 8, 6], 12=>[0, 11, 2, 3, 4, 1, 8, 7, 5]}

Gen: 11
Queue Before: [11, 3, 8, 1, 7, 12, 5, 9, 0, 4, 10, 2, 6]
Linked: [[3, 7], [11, 5], [1, 9], [8, 0], [12, 10]]
Queue After: [4, 2, 6]
Link History: {0=>[1, 12, 2, 3, 4, 6, 5, 7, 10, 9, 8], 1=>[0, 2, 3, 4, 6, 8, 12, 11, 10, 7, 9], 2=>[3, 1, 0, 12, 11, 9, 10, 7, 4, 5, 6], 3=>[2, 4, 1, 0, 12, 11, 6, 9, 5, 8, 7], 4=>[5, 3, 6, 1, 0, 12, 8, 2, 9, 10], 5=>[4, 6, 7, 10, 8, 9, 0, 3, 2, 12, 11], 6=>[7, 5, 4, 8, 1, 0, 3, 10, 9, 11, 2], 7=>[6, 8, 5, 9, 10, 11, 2, 0, 12, 1, 3], 8=>[9, 7, 10, 6, 5, 1, 4, 12, 11, 3, 0], 9=>[8, 10, 11, 7, 2, 5, 3, 6, 4, 0, 1], 10=>[11, 9, 8, 5, 7, 2, 6, 1, 0, 4, 12], 11=>[10, 12, 9, 2, 3, 7, 1, 8, 6, 5], 12=>[0, 11, 2, 3, 4, 1, 8, 7, 5, 10]}

Gen: 12
Queue Before: [4, 2, 6, 3, 7, 11, 5, 1, 9, 8, 0, 12, 10]
Linked: [[4, 7], [5, 1], [2, 8], [11, 0], [6, 12], [3, 10]]
Queue After: [9]
Link History: {0=>[1, 12, 2, 3, 4, 6, 5, 7, 10, 9, 8, 11], 1=>[0, 2, 3, 4, 6, 8, 12, 11, 10, 7, 9, 5], 2=>[3, 1, 0, 12, 11, 9, 10, 7, 4, 5, 6, 8], 3=>[2, 4, 1, 0, 12, 11, 6, 9, 5, 8, 7, 10], 4=>[5, 3, 6, 1, 0, 12, 8, 2, 9, 10, 7], 5=>[4, 6, 7, 10, 8, 9, 0, 3, 2, 12, 11, 1], 6=>[7, 5, 4, 8, 1, 0, 3, 10, 9, 11, 2, 12], 7=>[6, 8, 5, 9, 10, 11, 2, 0, 12, 1, 3, 4], 8=>[9, 7, 10, 6, 5, 1, 4, 12, 11, 3, 0, 2], 9=>[8, 10, 11, 7, 2, 5, 3, 6, 4, 0, 1], 10=>[11, 9, 8, 5, 7, 2, 6, 1, 0, 4, 12, 3], 11=>[10, 12, 9, 2, 3, 7, 1, 8, 6, 5, 0], 12=>[0, 11, 2, 3, 4, 1, 8, 7, 5, 10, 6]}

Gen: 13
Queue Before: [9, 4, 7, 5, 1, 2, 8, 11, 0, 6, 12, 3, 10]
Linked: [[4, 11], [9, 12]]
Queue After: [7, 5, 1, 2, 8, 0, 6, 3, 10]
Link History: {0=>[1, 12, 2, 3, 4, 6, 5, 7, 10, 9, 8, 11], 1=>[0, 2, 3, 4, 6, 8, 12, 11, 10, 7, 9, 5], 2=>[3, 1, 0, 12, 11, 9, 10, 7, 4, 5, 6, 8], 3=>[2, 4, 1, 0, 12, 11, 6, 9, 5, 8, 7, 10], 4=>[5, 3, 6, 1, 0, 12, 8, 2, 9, 10, 7, 11], 5=>[4, 6, 7, 10, 8, 9, 0, 3, 2, 12, 11, 1], 6=>[7, 5, 4, 8, 1, 0, 3, 10, 9, 11, 2, 12], 7=>[6, 8, 5, 9, 10, 11, 2, 0, 12, 1, 3, 4], 8=>[9, 7, 10, 6, 5, 1, 4, 12, 11, 3, 0, 2], 9=>[8, 10, 11, 7, 2, 5, 3, 6, 4, 0, 1, 12], 10=>[11, 9, 8, 5, 7, 2, 6, 1, 0, 4, 12, 3], 11=>[10, 12, 9, 2, 3, 7, 1, 8, 6, 5, 0, 4], 12=>[0, 11, 2, 3, 4, 1, 8, 7, 5, 10, 6, 9]}
 

 

Notice that it takes 14 generations to go through them all (number of worlds + 1), and the last generation only has two portals open between #4-#11, and #9-#12, while the rest of the worlds are portal-less.  Depending on which is stricter requirements, you can keep it to 13 generations before reseting the link history just knowing that #4-#11 and #9-#12 will never have portals together.


In Topic: Did you know GDNet turned 17 today?

19 June 2016 - 01:19 AM

Happy Birthday!

 

A floorcaek is well deserved

 

http://i.imgur.com/kFK4w.jpg


In Topic: A game suitable to training a neural network?

17 June 2016 - 07:36 PM

I'd suggest you start with these:

 

Classic board games like checkers/othello. (I am not going to recommend chess or go due to its high branching factor)

Tic-tac-toe

 

The hard part of using NN in games is training it because games are interactive and have animations.  Once your game start using some kind of animation in which the NN has to respond at certain frame doing certain things, that's when it gets tricky.  Your game must be coded in such a way that it can be run in a endless loop with just the NN playing it.

 

The games above can be simulated easily without graphics, so that's why I recommend to start with those.


In Topic: how can neural network can be used in videogames

14 June 2016 - 12:54 PM

Strange that nobody mentioned this:


PARTNERS