Artificial Intelligence of Chess Games (5)--2048 Game AI Interpretation

Source: Internet
Author: User


Objective:
Busy all right, online search " game ai", see an article <<2048 game is the best algorithm? Take a look at the AI version of the author's answer >> article. And this article is just the same as the previous game of chess games ai corresponding. So have the idea, want to use it as an example to interpret, thus to the previous partial theory of the article to make a summary.
To undertake four blog posts:
(1). Evaluation function + Game tree algorithm
(2). Learning Algorithms
(3). Game Tree Optimization
(4). Game Ai's Landing
Maybe some people will wonder? 2048 is not a chess type? is the traditional game tree model applied to this? Sir, let us step by step to uncover the answer.

Guide:
This article is the best algorithm for <<2048 game? Take a look at the AI author's answers >> articles, as well as the AI code provided by the original author.
If you are interested, you can click the demo game link, you can check the source code link.
  

Modeling:
Before the game games, both sides of the game's status are equal. But there's only one player here, where's the opponent?
Let the human brain hole Open is, 2048 game AI designers, creative to the chess environment itself as the other side of the game .
Of course, the two sides pursued a different goal of victory:
Game player (AI): 2048 and 2048 more blocks appear
Chess Environment: Fill the game grid, so that 4 directions can not move
The game model has evolved into an information-complete chess problem. Traditional game trees and techniques have a natural niche.

evaluation function:
Based on the game experience, the author chooses the following evaluation factors:
(1) monotonicity : Refers to the box from left to right, from top to bottom are to follow the increment or decrement.
(2) smoothness : refers to each block and its direct adjacent square value of the difference, wherein the smaller the less smooth.
(3) number of spaces : The total number of spaces in the situation.
(4) Maximum number : The maximum number of the current situation, the characteristic is the positive factor.
Take a linear function and add a weight factor:

Static Evaluation FunctionAI.prototype.eval = function () {  var emptycells = This.grid.availableCells (). length;< C1/>var smoothweight = 0.1,      //monoweight   = 0.0,      //islandweight = 0.0,      mono2weight  = 1.0,      Emptyweight  = 2.7,      maxweight    = 1.0;  return this.grid.smoothness () * smoothweight       //+ this.grid.monotonicity () * Monoweight       //- This.grid.islands () * Islandweight       + this.grid.monotonicity2 () * Mono2weight       + Math.log (emptycells) * Emptyweight       + this.grid.maxValue () * maxweight;};

Review: The Top 3 measures the quality of a situation , and the maximum number of these items makes the game AI a bit more active and "risky". Weight factor setting and feature selection is actually a technical work, the author has his try and weigh it.

Game:
The decision-making process of game AI is the implementation of standard maxmin search and Alpha+beta pruning. All directions (up or down) will be tried.
However, in the game itself make a decision, not every space to try to fill in {2, 4}. Instead, the worst-case scenario is chosen as the pruning condition for the search branch. A number of search branches have been selectively discarded.

//Try a 2 and 4 in each cell and measure how annoying it was//with met    Rics from eval var candidates = [];    var cells = This.grid.availableCells ();    var scores = {2: [], 4: []};        for (var value in scores) {Scores[value].push (null) (VAR) in cells)        var cell = Cells[i];        var tile = new Tile (cell, parseint (value, 10));        This.grid.insertTile (tile);        Scores[value][i] =-this.grid.smoothness () + this.grid.islands ();      This.grid.removeTile (cell); }}//Now just pick out the most annoying moves var maxscore = Math.max (Math.max.apply (null, scores[2]), math.ma    X.apply (NULL, scores[4]));  for (var value in scores) {//2 and 4 for (var i=0; i<scores[value].length; i++) {if (scores[value][i] = =        Maxscore) {Candidates.push ({position:cells[i], Value:parseint (value, 10)}); }      }    }

For selective ignoring of search nodes , it is very controversial. In some cases, the chances of obtaining an optimal solution are lost. However, the depth of search has been greatly enhanced by cutting down many branches. ability to survive more powerful .

Iterative Deep Search:
Different JavaScript engines differ significantly in their performance, if time-limited searches are required. At this time the iterative deep search on the "stage".

Performs iterative deepening over the Alpha-beta searchAI.prototype.iterativeDeep = function () {  var start = (New D Ate ()). GetTime ();  var depth = 0;  var best;  do {    var newbest = this.search (Depth, -10000, 10000, 0, 0);    if (Newbest.move = =-1) {Break      ,    } else {best      = newbest;    }    depth++;  } while (new Date ()). GetTime ()-Start < minsearchtime);  Return best}

  The time-out judgment is done after each deep exploration , which may not be accurate or even very error-intensive . I'm still advocating the way that I talked about the implementation of the previous article .
In any case, the author basically meets the requirements of every 100ms decision-making step.

Summarize:
Several of the previous posts involved many points, all of which are reflected in the 2048 game AI. 2048 games as a non-typical game games, this is not quite suitable as a specific case to explain. But for the original author of Creative Thinking and modeling, we as the younger generation can learn more. It is also a good way to evaluate decision-making in the face of feedback-type scenes.
This article before writing, did not notice this blog post <<2048 AI program algorithm analysis >> existence. In the process of writing, drawing on this article, but also added some of their own understanding.

Written at the end:
  
If you think this article is helpful to you, please give it a little reward. In fact, I would like to try to see if blogging can bring me a little bit of revenue. No matter how much, is a kind of sincere affirmation to the landlord.

Artificial Intelligence of Chess Games (5)--2048 Game AI Interpretation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.