I just noticed that after your refactoring the logic to check if there is a draw by insufficient material is wrong. If there are no knights and the pieces are >= 4, the draw can happen only if all the bishops on the board are on the same color square.
If all the white bishops are on the light squares and all the black bishops are on the dark squares it’s still not a draw. Let me show you:
In this position black can make the move bishop a2, to which white can answer with bishop d5 checkmate.
// white has all bishops on light squares while black has all bishops on dark squares
let allWBLight = set.B & .dark == 0 // true
let allWBDark = set.B & .light == 0 // false
let allBBLight = set.b & .dark == 0 // false
let allBBDark = set.b & .light == 0 // true
(allWBLight && (allBBDark || allBBLight)) || (allWBDark && (allBBDark || allBBLight)) ->
(true && (true || false)) || (false && (true || false)) -> true //wrong
// as we just saw in the previous example this can't be true since it's not a forced draw
In addition to what I just said, there is also another problem. Let's say that white has 2...N bishops while black has none. The variables let allBBDark = set.b & .light == 0 and let allBBLight = set.b & .light == 0 will be true, which is not correct.
I hope everything is clear now. Let me know if you have any other doubt 😄
I just noticed that after your refactoring the logic to check if there is a draw by insufficient material is wrong. If there are no knights and the pieces are >= 4, the draw can happen only if all the bishops on the board are on the same color square. If all the white bishops are on the light squares and all the black bishops are on the dark squares it’s still not a draw. Let me show you:
In this position black can make the move bishop a2, to which white can answer with bishop d5 checkmate.
In addition to what I just said, there is also another problem. Let's say that white has 2...N bishops while black has none. The variables
let allBBDark = set.b & .light == 0
andlet allBBLight = set.b & .light == 0
will be true, which is not correct.I hope everything is clear now. Let me know if you have any other doubt 😄