I'm currently working on summarizing of all of my previous work into a single javascript chess library intended to provide an embeddable chess board (so one can include it into his website) empowered by chess engine analysis. And yeah, I'm NOT covering it in youtube series believe it or not (this was sarcasm). Despite normal people would most likely separate GUI and analysis (literally engine) parts into 2 files (instances) me, as a code monkey king bundle it all together. But obviously we can't reuse the single board instance for both - GUI and searching in a non-blocking manner, so I need to instantiate them in separate somehow. The solution I've considered is inspired by the encapsulation technique introduced in chess.js https://github.com/jhlywa/chess.js/blob/master/chess.js
The reason why I consider it is because I can leave my "all global variables" engine structure, which most people hate, but encapsulate it within a single object. The snippet below shows the architecture:
Code: Select all
// library
var Chess = function() {
// global to this object/function scope board array
var board = new Array(128);
...
// render board to HTML
render_board() { ... }
// search position
function search() { ... }
// public API
return {
render_board: function() { return render_board(); }
search: function() { return search(); }
}
}
Code: Select all
// create board instance
var board = new Chess() // it still can search but used only for handling GUI, move validation, etc.
// create engine instance
var engine = new Chess() // it still can work with GUI for instance is the same as above, but this one is used for search
// render board
board.render_board() // draws chess board on HTML page
// async position search
var best_move = new Promise(function() { engine.search() }); // searches for best move without blocking GUI thread
// interact with GUI when promise returns
best_move.then(/* interact with board object when search is done */)
Now the QUESTION ARISES:
Can I instantiate the number of Chess() object instances equal to the number of moves in the root position and search in parallel in this way?

