[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
How would you code an AI for Snakes and Ladders?
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 60
Thread images: 5
File: snakes-and-ladders.jpg (425 KB, 1283x1285) Image search: [Google]
snakes-and-ladders.jpg
425 KB, 1283x1285
How would you code an AI for Snakes and Ladders?
>>
I get it. I'm not laughing, but I get it
>>
Not possible, AI isn't that advanced yet.
>>
>>53063764
>>53063805

Isn't it a random dice game? No AI required
>>
>>53063837
you can choose to take a ladder or not, this opens up the game to strategy
>>
>>53063850
Isn't it always better to take a ladder?
>>
>>53063946
not always
>>
>>53063764
It's not like there's tactic to play that, why you need an AI to play win-by-luck game
>>
>>53063966
Why not? You can only take ladders when you land on the ladder starting space, and ladders always get you closer to the top.
>>
>>53063946
I'd think so, it's a race, you could miss 9 and 20 hoping to get 28, that's a bet not a strategy.
>>
>>53064003
Is it better to take the 9 ladder or wait and have a chance at the 28 ladder?
>>
>>53064003
but what if you land on a small ladder, which skips past a longer ladder?
>>
>>53063764
Please refrain from using coding as a verb to refer to programming. A code is a set of instructions a computer can execute, which are programmed by people that are aptly called programmers. Programmers program; they don't code.
>>
>>53064056
>muh semantics
>>
>>53064028
Better to take the sure ladder if you get the chance rather than possibly not get a ladder. The gain from the small ladders are enough that they're worth it.
>>
There is probably some statistics to whether some squares are more likely but
really?
>>
>>53064028
How many turns could it take to get from 9 to 28 or past it?
>>
>>53064067
Semantics make up an important part of programming, they can make a huge difference when it comes to readability and understandability, which in turn affects maintainability later down the line.
>>
let the AI gather information first
make a quadrillion runs and let the statistics decide in the final games whether to take a ladder or hope for a better ladder in the following turns

that's also how it works with the human brain
if you don't follow the steps above (get experience and then try again) it's all just randomised shit and AI or 3yo shitter who has never played that game doesn't matter
>>
Can we use an AI to construct a new snakes and ladders game with a more complex structure?
>>
I would code it in python
>>
>>53064186
It's possible but actually making a board game is NP-complete
Your AI may propose a solution and we can verify that it works but we can't verify that it's the best solution there is
>>
>>53064186
i have this insanely unexplainable feeling that they'll never find any better structure.
i bet this is the best design.

>>53064232
oh you...
>>
so, why don't we start writing the algorithm right here?

i don't know too much about programming. but i guess, we'll need a 10 by 10 array?
>>
>>53064056
C is a code that is translated to another code

One is read by humans, the other by computers
>>
>>53064242
Depends on the board game
>>
>>53064275
C is a programming langauge, which humans program in.
>>
>>53064300
how so?
Name one board game that can be improved to perfection where we can verify in polynomial time that it's the best solution there is and ever will be
>>
>>53064343
Imagine you have a 10 by 10 board. On some tiles there are coins. You have to walk from the starting position at (0,0) (upper left corner) to the finish position (9,9), but you may only walk down or to the right. Find the path that maximizes the amount of coins you pick up.

A dynamic programming solution exists for this.
>>
File: Eels_&_Escalators.png (4 MB, 1627x1079) Image search: [Google]
Eels_&_Escalators.png
4 MB, 1627x1079
>>53063764
Same way you'd code an AI for Eels and Escalators
>>
>>53063764
>How
Vim + tmux + cpp compiler?
>>
>>53063764
reinforcement learning
>>
>>53064390
>cpp
>>
>>53063764
A*
>>
>>53063764
are there different designs of this game in different countries?
i don't remember seeing a snake head on 99.
in my version snake head is at 98 and takes you back down to single digits, like a huge fuck you.
>>
>>53064376
that's a different problem senpai
>>
>>53064454
He asked for any board game
>>
>>53064472
yeah but the original question was to make our AI return a "more complex" version of our game rather than finding a path
two entirely different problems and I don't even get how you got from one to another
>>
>>53064430
10x10 board
10 snakes - at least 1 having a more than 85 point shift
10 ladders - at least 1 having a more than 85 point shift
6 sided dice
opens with 1 or 6
has to get the exact number that just takes you over by 1 in the last row. [if you are at 95, a six will take you over, 5 takes you at 100 and to win you have to get 1]


int dice = roll_dice(randomize(6)); //or however you use randomize
pl_pos = pl_pos+dice;
int i=0;
if ( pl_pos != snake_mouth[i] && i<=9 ) {
boolean move_on=true;
i++;
}
else
{
//find what snake_mouth[i] 's snake_tail[i] is
}

//or you could look for a working code online
>>
Best way to figure this out would be to run simulations of the game in which the AI has every different combination of ladders skipped and ladders taken (there are 2^8 strategies with 8 ladders) and find the average amount of turns each startegy takes to complete.

I guess you could also solve it with mathematics but the number of different possible game scenarios is infinite and tiresome.
>>
>>53064706
Pesky snake loops
>>
>>53063850
For each field with a choice I would simulate a few thousand random to get a winning probability for each. I'd store that and use it for decisions.
>>
>>53064493
Got to it because he asked that while trying to defend the idea that any board game must be NP-complete
>>
>>53064706
Just use an absorbing markov chain
>>
>>53064976
Not familiar with the concept, seems super applicable here though.
>>
File: Question Clear.png (4 KB, 500x500) Image search: [Google]
Question Clear.png
4 KB, 500x500
>>53064099
>>53064120
>>53064028
>>53064031
>>53064003

Let's use a simple expected outcome calculation.

Consider the following:
Dice has 6 sides
You land on 9 and can go to 31 guaranteed.
>This advances you 22 spaces.
Now let's say we have a worst case senario w/ a 1/6 chance of landing on space 28 that takes you up to 84 (I don't feel like doing the actual calculation).
The expected outcome is the product of the probability and the difference
>1/6 * 56 = 9.33.

The rational thing to do is to take the 9 ladder.

Now what chance do we need to land on a the 28 to make it worth it?
22/56= 39%
While it is dangerous to say this, it appears obvious that we will never have a 40% chance of landing on the 28 spot.

Always take the ladder if you have the chance. No AI required
>>
>>53064118
adjacency matrix to the nth power gives the probability of being on a square after n steps

there is some pretty python code with good visualisations floating around on some blog i saw years ago
>>
>>53066582
How about for a randomly generated S&L board, where it is possible to get a fluke of say 5 ladders in a row?
How about 5 ladders followed by a snake back to the start?
>>
>>53066791
I was assuming a static board.

Dynamic games is a different story.
>>
>>53064028
Then it’s all probability calculation. The AI coding doesn’t take a code monkey, it takes a math monkey.
>>
>>53066791
That would be retarded. Even if you allowed that kind of shit you'd just have to have the "AI" look to see where the end of the ladder would land them, and if it's ahead of where they are it'd be better to take the ladder.

That's not even really getting into AI. It's still just dice and "will it move me forward?" To call that AI would be a stretch
>>
Daily reminder of how easily baited codemonkeys are into solving menial tasks
>>
File: nobody gives a shit.gif (1 MB, 640x360) Image search: [Google]
nobody gives a shit.gif
1 MB, 640x360
>>53064304
>programming
>coding
>writing

who fucking cares what you call it?
>>
>>53071148
nobody has coded anything you nig
>>
>>53063764
Ask alex lamb.
>>
>>53065055
Such a model does not have enough capacity to perform stateful decisions in s&l because it would violate the markov condition.
>>
randum number gen (1,7) 7 quits and throws a tanty throws board across room - get mum to start game over
>>
>>53071247
>dae le frank xD so fannay

back to dumblr, kiddo
>>
>>53064415

Underrated post
>>
>>53064966
>actually making a board game is NP-complete
reading comprehension, bruh

>>53064242
>>53064186
making a board game is hard, but making one that already exists more complex isn't. It should be possible just by adding rules.
Thread replies: 60
Thread images: 5

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.