Workshop › Chess › Step 45 of 48
Alpha-beta cuts sooner when good moves are tried first. A cheap guess: moves that capture a big piece. Sort the moves by the value of what they capture, biggest first.
```js
// Trying captures of big pieces first lets alpha-beta skip more of the rest.
const gain = (m) => (board[m.to[0]][m.to[1]] ? VALUES[board[m.to[0]][m.to[1]][1]] : 0)
moves.sort((a, b) => gain(b) - gain(a))
```gain(m) is the value of the piece on the target square, or 0 if it is empty.sort with (a, b) => gain(b) - gain(a) puts bigger gains first: a negative result keeps a before b.In search, under the depth === 0 line, write the comment and the two lines.
Skills: Arrays and objects
← Alpha-beta: skip what cannot matter The computer plays black →