An Othello Ace written in JavaScript
First of all, this code was not written by me, but the comments were added by me.
Second, this code currently only uses alpha-beta pruning, which is still weak and has a lot of room for optimization. But the code is written very clearly. If there are friends who are interested in the subject of human-machine chess but haven’t gotten started yet, this code is great as an example.
Third, currently computers can only search 3 layers. I think with the addition of iterative deepening and history-inspired algorithms, it will not be a problem to search 5 layers. Modern JavaScript performs well.
Fourthly, the author has demonstrated many techniques in the code, which are worth learning and learning from. It is easy to understand the code even if you don’t understand JavaScript (I don’t understand either).
Fifth, try the chess power of this AI: html">http://shaofei.name/OthelloAI/othello.html
The following is the code:
view plaincopy to clipboardprint?
var AI = {};
new function(){
AI.Pattern= pattern;
// 8 offsets are defined
// You can simply add 8 points around any point to get The coordinates of
// -11 -10 -9
// -1 -9,-1,1,9,10,11];
function pattern()
{
// Fill the entire board with 0s
for(var i=0;i<100;i++)this[i]= 0;
// In the middle 4 squares, first place two black and two white chess pieces
this[54]=this[45]=1;this[55]=this[44]=2;
// Black net The number of winning pieces (black minus white), used in valuation.
this.divergence=0;
// The current moveable player is black
this.color=1;
// A few moves have been made
this.moves=0;
// Stable prototype
// 0 is a blank, 1 is a black chess, 2 is a white chess, and 3 is a border
// Expanding the 8 * 8 chessboard into 10 * 10 is a technique
// It can simplify the judgment of coordinate validity
var stableProto = [
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 0, 0, 0, 0, 0, 0, 0, 0, 3,
3, 0, 0, 0 , 0, 0, 0, 0, 0, 3,
3, 0, 0, 0, 0, 0, 0, 0, 0, 3,
3, 0, 0, 0, 0, 0, 0, 0 , 0, 3,
3, 0, 0, 0, 0, 0, 0, 0, 0, 3,
3, 0, 0, 0, 0, 0, 0, 0, 0, 3,
3, 0, 0, 0, 0, 0, 0, 0, 0, 3,
3, 0, 0, 0, 0, 0, 0, 0, 0, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3
] ]
// Loading state from an 8 * 8 board
this.load=function(arr)
{
for(var y=1;y<=8;y++)
Determine whether it can pass
// If it can, the current player can change
this.pass=function()
{ for(var y=1;y<=8;y++)
{ = 1;x<=8;x++) You can move, but you can’t even pass if(this.move(x ,y,this.color))
{U Return false;
}}}}}}
// Alert ("PASS");
// This is a technique, because the value domain of this.Color is {1, 2}
// so when you should be a color as color When it is 1, it will be 2 after executing the next statement. // When color is 2, it will be 1 after executing the next statement. This.color = 3 - this.color;
return true;
this.clone = Function () {
Function Pattern () {}
Pattern.prototype = this;
Return New Pattern (); "*" ,"o"]
var r="";
for(var y=1;y<=8;y++)
{ for(var x=1;x<=8;x++)
{ [this[y*10+x]]+” “;

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to use WebSocket and JavaScript to implement an online speech recognition system Introduction: With the continuous development of technology, speech recognition technology has become an important part of the field of artificial intelligence. The online speech recognition system based on WebSocket and JavaScript has the characteristics of low latency, real-time and cross-platform, and has become a widely used solution. This article will introduce how to use WebSocket and JavaScript to implement an online speech recognition system.

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

How to use WebSocket and JavaScript to implement an online reservation system. In today's digital era, more and more businesses and services need to provide online reservation functions. It is crucial to implement an efficient and real-time online reservation system. This article will introduce how to use WebSocket and JavaScript to implement an online reservation system, and provide specific code examples. 1. What is WebSocket? WebSocket is a full-duplex method on a single TCP connection.

Introduction to how to use JavaScript and WebSocket to implement a real-time online ordering system: With the popularity of the Internet and the advancement of technology, more and more restaurants have begun to provide online ordering services. In order to implement a real-time online ordering system, we can use JavaScript and WebSocket technology. WebSocket is a full-duplex communication protocol based on the TCP protocol, which can realize real-time two-way communication between the client and the server. In the real-time online ordering system, when the user selects dishes and places an order

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

Introduction to the method of obtaining HTTP status code in JavaScript: In front-end development, we often need to deal with the interaction with the back-end interface, and HTTP status code is a very important part of it. Understanding and obtaining HTTP status codes helps us better handle the data returned by the interface. This article will introduce how to use JavaScript to obtain HTTP status codes and provide specific code examples. 1. What is HTTP status code? HTTP status code means that when the browser initiates a request to the server, the service

Usage: In JavaScript, the insertBefore() method is used to insert a new node in the DOM tree. This method requires two parameters: the new node to be inserted and the reference node (that is, the node where the new node will be inserted).
