10 ms·
Chess: Who will win in this riveting game of Math.random() vs. Math.random()?
- lmm 12y agoSeems like it always queens pawns; I'd hoped to see some exciting random promotions :/.
- pedrocr 12y agoJust saw it promote to bishop :)
- Elhana 12y agoTwo 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.
- stouset 12y agoI just saw a promotion to a knight.
- emmelaich 12y agoThis is also a fascinating phenomenon. To some of the moves really didn't look random -- but of course there were. We imprint our own flawed notions of randomness on everything.
- cgriswald 12y agoIn the game I watched, I saw two promotions to queens, a knight, and a rook.
- zetazzed 12y agoI 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 12y agoI 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.
- schoen 12y agoI was fairly disturbed by the repeated pointless sacrifices of major pieces (which typically aren't even accepted: black offers its queen in exchange for nothing, and white doesn't capture it!).
- gjm11 12y agoYes. I found it really quite distressing to watch.
- cgriswald 12y agoI 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.
- jrockway 12y agoAt least it's no longer allowed to promote to an opponent's piece. Otherwise, I imagine the computer would do that 50% of the time.
- raverbashing 12y agoYeah, now just plug a genetic algorithm to it, and let it evolve.
- acadien 12y agoBecause 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.
- afro88 12y agoIf it's impossible to checkmate then it's a stalemate. So if one side has one king and the other side one king (or even one king and a pawn, bishop, knight or rook) then it's a stalemate and the game ends. edit: forgot you can checkmate with just a king and a queen
- cozzyd 12y agoPawn wouldn't be stalemate because it can be promoted to a queen. I think it's also possible to checkmate with a rook + king (if you corner the king and have your king cover the escape route from check).
- umanwizard 12y agoYup, you're right! The algorithm works like this: (each "move" is an implicit "continue" in the pseudocode) while no checkmate: If your rook is about to be taken, move it to the other end of the current rank. If the enemy king is on rank n and your rook is anywhere but rank n-1, move your rook to rank n-1 (unless it can then be taken, in which case move it to the end of its current rank.) If your king is anywhere but rank n-2, move towards there. If your kings are on the same file, advance the rook to rank n (unless it can be taken...) If |file of your king - file of opponents king| is odd, make a wasted move with the rook (keeping it on the same rank). If you've gotten this far, move your king towards the opponent's king (staying on the same rank n-2).
- caractacus 12y agoWhite 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.
- pcthrowaway 12y agoFirst 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
- Svenstaro 12y agoWhite caged its own king in a8 by putting pawns in a7 and a6 while black king just chilled about in c8. Checkmate!
- yuhong 12y agoAlso would be fun to do with the secure random generator in Web Crypto.
- rectangletangle 12y agoIt's truly a spectacle to witness the elegant tactics of Math.random().
- z3t4 12y agoThe 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.
- emmelaich 12y agoVery 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.
- emmelaich 12y agoIt's interesting how closely the midgame resembled a real midgame. But superficially. Better than some chess arrangements you see in movie scenes.
- kevining 12y agoI 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.
- joshvm 12y agoSome 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!
- jrockway 12y agoI do play chess and found watching this rather painful. I guess the next thing to do is instead of random: if you can capture a piece of equal or higher value: do so. This is, of course, not a particularly good chess strategy, but would probably be less painful to watch.
- jerf 12y agoThe 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.
- deleted 12y ago[deleted]
- jedunnigan 12y agoTo 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.
- caycep 12y agoThis is almost as good as the goldfish vs. goldfish Street Fighter battle...
- lewapkon 12y agoSome risky moves from the white and we’ve got a pretty quick checkmate https://www.dropbox.com/s/q66h70kuauog3zq/Screenshot%202015-01-26%2001.37.56.png?dl=0 https://www.dropbox.com/s/q66h70kuauog3zq/Screenshot%202015-...
- Lrigikithumer 12y agoIs the board continuously flashing for anyone else? Mac OSX 10.10.1 Safari.
- andyidsinga 12y agosurprising how riveting it is.
- chrisoakman 12y agoNever 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 :)
- PhoenixWright 12y agoSurprised nobody has responded to you. Good job, I really enjoyed seeing your work.
- cperciva 12y agoI 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.
- furyofantares 12y agoI 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.
- roryokane 12y agoIt 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.
- Someone 12y agoOne 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.
- randomnumber53 12y agoHow is this different from an opening tree?
- Someone 12y agoIt would be agnostic of how far the game has progressed (if 1. …c5 is a good reply to 1. e4, it also would be considered a good reply to 75. e4) It would also be used in end games.
- Xeoncross 12y agoI'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 12y agoYou could probably just drop moves that are below a certain threshold after every k games.
- halfcat 12y agoChess engines make use of similar Markov-chain-like techniques, such as killer [1] and history [2] heuristics. They also use win-loss-draw outcomes from millions of grandmaster games in a similar way to build an opening database, to guide them through the opening, the phase which they are weakest at. [1] https://chessprogramming.wikispaces.com/Killer+Heuristic https://chessprogramming.wikispaces.com/Killer+Heuristic [2] https://chessprogramming.wikispaces.com/History+Heuristic https://chessprogramming.wikispaces.com/History+Heuristic
- halfcat 12y agoI 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 12y agoThose 15 stalemates were probably other people running bots :)
- xigency 12y agoThis 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/
- guy_c 12y agoI 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.
- curiously 12y agothere's a black king and a white king and white knight and its just stuck...
- ninjakeyboard 12y agoAre you guys watching this? eats popcorn I've been watching for like 3 hours and nobody won yet.
- JayXon 12y agoIt's impossible, I watched it for several minutes, then it stopped moving, not sure why.
- cpeterso 12y agoSome 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.
- bane 12y agoOut of curiosity, anybody know the relative strength of this vs. other real engines?
- shultays 12y agoUh, zero?
- bnegreve 12y agoProbably, 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 12y agoI 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)
- UXDork 12y agoI'm guessing white wins more often... ;)
- UXDork 12y agoThe 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 )
- justintbassett 12y agoOh 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 12y agoThat 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.
- triangleman83 12y agoAh the classic fool's mate
- TheRedBarron 12y agoI made something that did stats on this a few months ago see it here https://barronwasteland.wordpress.com/2014/08/04/random-move-chess-aka-infinite-monkey-chess/ https://barronwasteland.wordpress.com/2014/08/04/random-move...
- kahirsch 12y agoThose statistics are surprising.
- TheRedBarron 12y agoCorrect, hence part two was required. This went into some of the possible errors that came up https://barronwasteland.wordpress.com/2014/12/13/infinite-monkey-chess-part-ii/ https://barronwasteland.wordpress.com/2014/12/13/infinite-mo...
- pcvarmint 12y agoIt seems like draw by insufficient mating material needs to be separated out from draw by repetition, although if you only enforce draw by repetition, it will inevitably happen on a board with insufficient mating material. ChessPeace says "Draws by insufficient mating material is not available because of insufficient theory dealing with the non-standard pieces". "Play with many new pieces with new abilities not seen in standard chess" It seems that if the board is currently limited to standard pieces, it should use the standard rules for draws by insufficient mating material. How hard is that? No pawns, no non-standard pieces, no queen, no rook, less than two bishops, and no knight + bishop.
- kristopolous 12y agoFinally a chess engine I can beat.
- mikecmpbll 12y agowhat .. why ..
- Aardwolf 12y agoVery 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?
- deleted 12y ago[deleted]
- pestaa 12y agoSo, when exactly did you record my average chess play?
- fmax30 12y agoSo 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
- tempodox 12y agoObviously, Math.random() must win inevitably.
- annnnd 12y agoOooo, 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 12y agoYou can play bots on FICS if you disclose it. https://chess.stackexchange.com/questions/8066/is-it-possible-to-play-vs-bots-on-fics https://chess.stackexchange.com/questions/8066/is-it-possibl... 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.
- Zisko 12y agoThis was INCREDIBLY frustrating to watch, even as an amateur chess player. Fun project though!
- pagnotta 12y agoI wonder how long it would take to run all the possible games, assuming there is no sleep time between moves.
- mytummyhertz 12y ago$100 to the first person to calculate the expected probability of a checkmate
- tarblog 12y agoTo what precision? ;)
- clafferty 12y agoTheres a bug in this when Math.random() === 1
- clafferty 12y agoTheres a bug in this when Math.random() === 1