private static void RefreshChessPaths(IBoardState <ChessPieceEntity> boardState, Colours whoseTurn) { // NOTE: Kings cannot move in to check, so we regenerate their state last so the know // all of the enemy piece attack paths var nonKings = boardState.GetItems().Where(i => i.Item.EntityType != (int)ChessPieceName.King); var kings = boardState.GetItems().Where(i => i.Item.EntityType == (int)ChessPieceName.King).ToList(); boardState.RefreshPathsFor(nonKings); // NOTE: Kings can't move next to each other, so we update the enemy kings state first so that we can // so when regen the friendly kings state it knows where the enemy kings can move to, and therefore // where it cannot if (whoseTurn == Colours.White) { boardState.RefreshPathsFor(kings.Where(k => k.Item.Owner == (int)Colours.Black)); boardState.RefreshPathsFor(kings.Where(k => k.Item.Owner == (int)Colours.White)); } else { boardState.RefreshPathsFor(kings.Where(k => k.Item.Owner == (int)Colours.White)); boardState.RefreshPathsFor(kings.Where(k => k.Item.Owner == (int)Colours.Black)); } }