
Chess: Who will win in this riveting game of Math.random() vs. Math.random()? - idiotclock
http://chessboardjs.com/examples#5002
======
acadien
Because check mate is a very small subset of possible moves at the end game,
I'm guessing the vast majority of games will end(?) with 2 kings moving around
randomly for all of time.

This assumes most games will make it past the hump of mid game where its
possible the king's motion will be limited and a checkmate can erroneously
happen, I suspect this is a rare case as well.

On a side note I wonder what kind of useful information could be mined from a
huge set of random-random games. Maybe the relative power of each piece in
terms of the number of pieces it captures on average? Also with some heuristic
tweeks you could probably start exploring the power of various openings. Of
course then its no longer random-random.

~~~
hibikir
It's not just random vs random. Two extremely weak players will take hours to
finish a won game, because the player with the major material advantage does
not know how to win!

When teaching kids, it's not uncommon to, after teaching them how to move all
the pieces, spend time teaching them how to perform the most basic of mates:
KQ vs K, KRR vs K, KR vs K. Only after those three are mastered we have a good
opportunity of having beginner games ending in anything other than a
stalemate.

~~~
omegaham
I still don't know how to checkmate with two bishops. I mean, I've read how to
do it, but if you stuck me in an endgame situation, I'd probably draw.
Luckily, I have never actually had an endgame with a king and two bishops
versus a king. Same thing with king, knight, and bishop.

~~~
narag
I have a humble level and did checkmate both with two bishops and with bishop
and knight... yes, I've found both finals. I had learned the mecanics years
before, didn't remember exactly how, but it wasn't so difficult to find the
path with enough time.

What I don't want to find is queen vs. rook. I played once queen and pawn vs.
rook and won, but it was _painful_. It seems there are some masters that are
specialists in drawing in this positions, even if it should always be a win.
Computers with end tables have not this problem.

~~~
antaviana
The mate King-Bishop-Night vs. King is a bit elaborate.

From a random position on the keyboard, you typically need around 20-25 moves
to achieve it, and there is a rule that draws a game after 50 moves without
any pawn moves.

I've seen an International Master offer draw to his opponent in KNB + K game
because he didn't remember what the winning method was (I suposo that after 5+
hours playing your eroded mindset also plays a role.

~~~
narag
I did remember the general strategy: take the opponent's king to a corner of
the same colour as the bishop. There are a couple of moves that must be
thought carefully. But the rest comes very naturally, provided you've
practiced it a few times.

------
chrisoakman
Never thought this comment would end up on HN when I wrote it ;)

I remember writing this example and being mesmerized watching the games
progress. I think I made an alternate version that speed up the time and
opened a handful of browser tabs to watch the games. Most of them do end up in
insufficient piece draws or the 50-move rule.

Glad to see others are enjoying it :)

~~~
cperciva
_I think I made an alternate version that speed up the time and opened a
handful of browser tabs to watch the games. Most of them do end up in
insufficient piece draws or the 50-move rule._

I also made an alternate version which runs faster, and I added some code to
count games. About an hour on Chrome got me to this point:

    
    
        44 white wins.
        415 ties.
        41 black wins.
        500 games played.
    

EDIT: Another hour, and the stats are now:

    
    
        74 white wins.
        847 ties.
        79 black wins.
        1000 games played.

~~~
annnnd
4 hours later, how does it look now?

I would expect that white/black position would be very similar in results (for
random games only, of course).

~~~
cperciva
I stopped it running after 2 hours.

------
Someone
One thing that is on my (way too long) list of things to try is n-gram chess.
1-gram chess would, for every move from black, have a dictionary of (following
move, win probability) pairs, and it would pick one that is legal using the
win probabilities to generate a distribution (if there is a sure win, almost
always pick it; if there is a move that always lost before, pick it very
rarely)

You can start this of with empty dictionaries, and have the thing learn after
each game (let two copies play for a few days to get let them teach each other
how to play chess)

2-gram chess would improve on this by using (white move, black's reply) as the
key in such a dictionary.

I think that would make for better chess than this. For some N, N-gram chess
might even superficially look like the real thing at times.

~~~
Xeoncross
I'm trying to figure out how you could store this without having massive
dictionaries after a night of training games. I guess it's all just integers
which helps.

~~~
acadien
You could probably just drop moves that are below a certain threshold after
every k games.

------
zetazzed
I found myself getting mad at Math.random() pretty quickly. "Argh, you just
got to promote two pawns, and you made them both black bishops!?!? I oughta
fire you and hire an LFSR!"

~~~
Patrick_Devine
I had exactly the same reaction. I was thinking it was going to be hilarious
to watch, but it turned out to be extremely aggravating. The random pawn
promotion was particularly egregious.

I'm curious if other people had the same visceral reaction.

~~~
cgriswald
I did. White had two queens to black's none. It promoted a pawn and made it...
a knight. And it was all by itself too. That part was hilarious, but...

In the endgame black had only a king and a pawn and the pawn was hung up on
another pawn in the g column. Black's king was trapped in column a by two
white rooks in the b column. White managed to create a stalemate with black
king at a5 and white rooks at b4 and b6.

------
halfcat
I once wrote a chess engine that played completely random moves and let it
play on the Internet Chess Club against humans for a day. It played 1/0 games
(1 minute for all moves). The final result was 46 wins, 22 draws, and 446
losses.

Here's a breakdown.

* 446 losses by checkmate

* 23 wins by time forfeit

* 18 wins by resignation

* 5 wins by disconnection forfeit

* 15 stalemates

* 5 draws by insufficient material

* 2 draws by repetition

Obviously it never won by checkmate. The rest basically came down to whether
the human opponent figured out that it was playing against a bot.

~~~
libria
Those 15 stalemates were probably other people running bots :)

------
furyofantares
I briefly wondered why the King felt smarter than the other pieces before
realizing the rules prevent it from taking immediately risky moves or staying
in a risky position.

------
justintbassett
Oh wow, I thought it was a joke at first, my game was only a half-dozen moves:
[http://i.imgur.com/kmKQ2Wi.png](http://i.imgur.com/kmKQ2Wi.png)

~~~
libria
That position is close to the fastest mate, black in 2. Not something, you'd
stumble upon in actual play, but if novices ever move that f pawn early, you
can usually destroy that side.

------
guy_c
I forced white to always take a piece if it can. It initially tears black to
shreds, but then the lone Black king battles back and slowly picks off the
white pieces.

------
rectangletangle
It's truly a spectacle to witness the elegant tactics of Math.random().

------
lmm
Seems like it always queens pawns; I'd hoped to see some exciting random
promotions :/.

~~~
pedrocr
Just saw it promote to bishop :)

~~~
Elhana
Two bishops here. It gets boring when there is a few pieces left.. there is
hardly any chance random will actually win - it will keep moving around
forever.

------
ninjakeyboard
Are you guys watching this? _eats popcorn_ I've been watching for like 3 hours
and nobody won yet.

~~~
JayXon
It's impossible, I watched it for several minutes, then it stopped moving, not
sure why.

------
xigency
This is strikingly similar to a web interface for chess that I just made, even
down to the public domain icons. Really slick, but playing against randomized
opponents is not very thrilling. There are also limitations to just optimizing
for the best turn with one turn lookahead. Although I have to say the drag and
drop is better on this version, I think the problem of trying to find the best
move in a client-side web application is relatively tricky. The most naive
attempt might use a brute-force method, but this could lock up the web
browser. And using large data structures would be taxing, too.

link: [http://greg.team-duck.com/chess/](http://greg.team-duck.com/chess/)

------
TheRedBarron
I made something that did stats on this a few months ago

see it here

[https://barronwasteland.wordpress.com/2014/08/04/random-
move...](https://barronwasteland.wordpress.com/2014/08/04/random-move-chess-
aka-infinite-monkey-chess/)

~~~
kahirsch
Those statistics are surprising.

~~~
TheRedBarron
Correct, hence part two was required. This went into some of the possible
errors that came up

[https://barronwasteland.wordpress.com/2014/12/13/infinite-
mo...](https://barronwasteland.wordpress.com/2014/12/13/infinite-monkey-chess-
part-ii/)

------
roryokane
It is also interesting to play the Play Random Computer example
([http://chessboardjs.com/examples#5001](http://chessboardjs.com/examples#5001)),
and try to checkmate the random computer without losing a single piece.

It combines the fun of steamrolling the opponent with the strategy of planning
captures that leave your piece perfectly safe, or managing the board so that
the computer could take your piece but probably won’t.

------
joshvm
Some interesting things happen here, the queens almost always seem to go first
in my games (perhaps because of their freedom of movement they tend to end up
in dangerous territory quickly). Also lots of pawn promotions make the mid-end
games a lot more fun, although as the promotion is also random I've ended up
with unwinnable endgames (e.g. two knights).

I don't play chess beyond knowing the rules, but this is a lot more fun than
watching a tournament!

~~~
jerf
The random move is chosen by generating all legal moves, then choosing from
them. This favors pieces with more legal moves, and thus tends to favor the
queen the most. Compare with choosing from all pieces that have a legal move,
then choosing a legal move for that piece, which would favor a lot of pawn
motion, at least until they got themselves killed.

~~~
jedunnigan
To avoid the pawn favoritism you could first select a category of piece, then
a specific piece of that category and then finally select a legal move for the
piece in question. I think this would be the most even handed way to make the
game more entropic.

------
emmelaich
It's interesting how closely the midgame resembled a real midgame. But
superficially. Better than some chess arrangements you see in movie scenes.

------
lewapkon
Some risky moves from the white and we’ve got a pretty quick checkmate
[https://www.dropbox.com/s/q66h70kuauog3zq/Screenshot%202015-...](https://www.dropbox.com/s/q66h70kuauog3zq/Screenshot%202015-01-26%2001.37.56.png?dl=0)

------
fmax30
So i simulated 2 games and both of them had a result. Quite interesting, my
intuition says that there should be more draws but guess i am wrong. [1]
[http://imgur.com/rN1zfDD,sQXY6zQ](http://imgur.com/rN1zfDD,sQXY6zQ)

------
Zisko
This was INCREDIBLY frustrating to watch, even as an amateur chess player. Fun
project though!

------
kristopolous
Finally a chess engine I can beat.

------
kevining
I just had black pull out an epic victory over white in truly random fashion:
[http://imgur.com/9CTukc5](http://imgur.com/9CTukc5)

I'm also curious how rare a victory is here, and if it can be modeled with
math.

------
emmelaich
Very dramatic! One plucky white pawn made it all to end before getting
slaughtered.

The two queens got _very_ friendly before the white king killed the black
queen in a fit of jealousy.

Meanwhile one black knight just stood off in the corner watching. Waiting.

------
caractacus
White down to King, Black with Bishop, King, Knight, pawn promoted to Queen...
but oh, the mistakes. White swept up piece after piece and could Black still
take it with a King-Knight combination? No. No he couldn't. Stalemate.

------
Aardwolf
Very original and fun :)

Near the end of the game the probability of something interesting happening
decreases. Maybe in the end it could at least prune out some moves and choose
randomly only amongst those that make pieces go closer to each other?

------
annnnd
Oooo, that makes me want to use genetic algorithms just to see if I can come
up with a great chess player... Is there an online tournament where I can
match my algorithm against others?

~~~
schoen
You can play bots on FICS if you disclose it.

[https://chess.stackexchange.com/questions/8066/is-it-
possibl...](https://chess.stackexchange.com/questions/8066/is-it-possible-to-
play-vs-bots-on-fics)

I guess you would want to program it to only play against other bots, and many
of the other ones are probably quite strong (since they're based on relatively
advanced chess software). So maybe that's not the ideal environment for
starting from zero.

------
pcthrowaway
First game I watched and I was expecting stalemate, but down to just a pawn
(f2) and a king (b3), white checkmated the opposing king (at b1) by promoting
the pawn to a queen

------
cpeterso
Some ideas:

* host a tournament of many different PRNG seeds.

* generate long strings of moves (random numbers) up front and then use a genetic algorithm to breed and mutate the winning strings.

------
z3t4
The computer could probably store moves that ended up in a win. Or collecting
statistics on what moves have a higher chance ending up in a win.

------
Svenstaro
White caged its own king in a8 by putting pawns in a7 and a6 while black king
just chilled about in c8. Checkmate!

------
pagnotta
I wonder how long it would take to run all the possible games, assuming there
is no sleep time between moves.

------
bane
Out of curiosity, anybody know the relative strength of this vs. other real
engines?

~~~
shultays
Uh, zero?

~~~
bnegreve
Probably, but is it that obvious? Having an opponent that is not even _trying_
to win is much harder to predict.

I've heard several poker players saying that it's hard to play against
novices, because they do nonsense.

Surly there is some game theory that says something about this. Anyone?

~~~
majc2
I wouldn't have thought so, because there isn't the same element of unknown
information that there is in poker (i.e. I don't know your hand in Poker), but
I know the board and if you're just playing random moves, then I can probably
use some variation of Scholars mate to end the game early. (some beginners
keep playing it until they finally reach a level that their opponents know how
to defend against it)

------
mytummyhertz
$100 to the first person to calculate the expected probability of a checkmate

~~~
tarblog
To what precision? ;)

------
caycep
This is almost as good as the goldfish vs. goldfish Street Fighter battle...

------
Lrigikithumer
Is the board continuously flashing for anyone else? Mac OSX 10.10.1 Safari.

------
yuhong
Also would be fun to do with the secure random generator in Web Crypto.

------
pestaa
So, when exactly did you record my average chess play?

------
clafferty
Theres a bug in this when Math.random() === 1

------
tempodox
Obviously, Math.random() must win inevitably.

------
UXDork
I'm guessing white wins more often... ;)

------
andyidsinga
surprising how riveting it is.

------
mikecmpbll
what .. why ..

------
curiously
there's a black king and a white king and white knight and its just stuck...

------
UXDork
The real question is if these wins would change as a result of "global
consciousness"

(Global consciousness project is a bunch of computers generating random
numbers all over the world that seem to spike when catastrophes occur
[http://en.wikipedia.org/wiki/Global_Consciousness_Project](http://en.wikipedia.org/wiki/Global_Consciousness_Project)
)

