Chess ai typically uses the "minimax algorithm" to decide its best move. This basically loops over all the pieces and plays them, then looks at all the outcomes and scores it, then does the same for all the player pieces. Thats a lot of calculations. It then picks the move with the best outcome. It does this a number of turns ahead. The more turns it looks ahead the smarter the ai is, but the more calculations it has to do.
This is something that events are not good at and is also very slow in c3, thats why you need to use js.