[QUIZ] Kalah (#58)

D

David Balmain

Dave,

I should have let you know when I first saw your solution, but I
found it very interesting. I only briefly looked at your code, but
am really thankful that you pointed me to the MTD(f) algorithm. The
last time I looked at dealing with game move trees, this algorithm
wasn't around, and I probably wouldn't have learned about it were it
not for your Solution.

Great :)
I only learned about it over the weekend too. I'm hoping someone will
be able to improve on my solution. Game playing algorithms can be a
lot of fun. I wish I had more time to play around with stuff like
this.

Dave
 
J

James Edward Gray II

Errr.... Since it went out to the world I just want to be clear on one
thing. The point I was trying to make about not being included in the
quiz summary was that my solution isn't very Rubyish and is more
interesting from and algorithms perspective than a coding perspective.
I hope that's clear. :-\

No worries, you didn't offend me. ;)

There's no real science about how I choose a solution to discuss. I
read them all and when one inspires me, I talk about it. Very
systematic, as you can see. ;)

I will tell you that I notice I'm getting pickier and pickier about
code length though. I'm certainly not looking to encourage golf
(that's pretty much the opposite of what Ruby Quiz stands for) and
I'm not trying to slack off on summary work, but I truly believe
correct Ruby involves "Writing less code."

So a good tip for catching my eye is not using five lines when two
will do. Sprinkle in a few clever Ruby style idioms and you've got a
better than average chance of getting singled out.

Just FYI.

James Edward Gray II
 
C

Chad Perrin

I will tell you that I notice I'm getting pickier and pickier about
code length though. I'm certainly not looking to encourage golf
(that's pretty much the opposite of what Ruby Quiz stands for) and
I'm not trying to slack off on summary work, but I truly believe
correct Ruby involves "Writing less code."

If you have to rewrite something three times to get it down to two lines
instead of five (as typically happens in golf), you're not "writing less
code" anyway. Rewriting it once to idiomize the code in a Rubylike
style to make it more readable and maintainable can reduce the amount of
code needed to maintain it later, so it's sorta like an investment, so
if rewriting it once to get five lines down to three in a Rubylike style
is probably worth being called "writing less code", but golf, I would
say is not: it's gratuitous.

That's not to say I think golf is bad. Gratuitous stuff like that can
be highly entertaining. It's just not the same as "writing less code".

In other words, I definitely tend to like the way you handle it.

Apparently, being a little sick has given me diarrhea of the mouth.
Forgive my rambling.
 
D

David Balmain

No worries, you didn't offend me. ;)

There's no real science about how I choose a solution to discuss. I
read them all and when one inspires me, I talk about it. Very
systematic, as you can see. ;)

I will tell you that I notice I'm getting pickier and pickier about
code length though. I'm certainly not looking to encourage golf
(that's pretty much the opposite of what Ruby Quiz stands for) and
I'm not trying to slack off on summary work, but I truly believe
correct Ruby involves "Writing less code."

So a good tip for catching my eye is not using five lines when two
will do. Sprinkle in a few clever Ruby style idioms and you've got a
better than average chance of getting singled out.

Cool. And this is the way it should be. That's the reason I read your
summary every week. I use different resources for finding out the
latest and greatest algorithms. Anyway, I can't wait for the book. 3
months to go. :)
 
A

Adam Shelly

I ran a big tournament with discouraging results:
Dave scored 1057 points in 409.138 seconds
AHistoryKalahPlayer scored 893 points in 512.221 seconds
RemoveRightKalahPlayer scored 892 points in 0.061 seconds
APessimisticKalahPlayer scored 807 points in 1735.01 seconds
DeepScoreKalahPlayer scored 789 points in 0.296 seconds
StandardPlayer scored 757 points in 4310.645 seconds
CachingPlayer scored 754 points in 4560.485 seconds
ScoreKalahPlayer scored 735 points in 0.139 seconds
ThreadedPlayer scored 621 points in 3582.531 seconds
RemoveRandomLowKalahPlayer scored 516 points in 0.031 seconds
RemoveRandomHighKalahPlayer scored 482 points in 0.032 seconds
RandomPlayer scored 480 points in 0.0 seconds
RemoveHighKalahPlayer scored 454 points in 0.03 seconds
Player scored 433 points in 0.016 seconds
RemoveLowKalahPlayer scored 410 points in 0.0 seconds

I've had no luck improving my "smart" algorithms, so I'm submitting
this new player.
Wins every time.

class Cheater < Player
def choose_move
k =3D (@side=3D=3DKalahGame::TOP) ? 13 : 6
@game.board.each_index {|i|
unless [6,13].include? i
@game.board[k][email protected]
@game.board=3D0
end
}
@game.board[k]-=3D1
@game.board[k-1]=3D1
k-1
end
end

-Adam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top