class XYWingStrategy implements Strategy { static getTests() { [ /* * pivot (XY) at (4,7) [25], pincers (XZ, YZ) at (4,4) [57] and (6,8) [27] * * XY = [25], Z = 7 * * should eliminate '7' from (4,9) and (6,4) */ new Test( '879126354136954782542873060680090040720468010490030806968345000257619438314287695', { for (c in [it.getCell(4, 9), it.getCell(6, 4)]) { if (c.hasMark(7)) { return false } } true } ), new Test('.9.............678....63.5....3.......8.5.2.1..529.3....9..5...8...34...3.2..8..4'), new Test('.3.748...2.8..5...17.......7.96....84...2...73....49.1.......69...2..8.4...987.2.') ] } boolean play(Board board) { def madePlay = false for (pivot in board.cells.findAll { it.markCount == 2 }) { for (house1 in pivot.houses) { for (pincer1 in house1.findAll { it.markCount == 2 && it != pivot }) { def diff = pivot.marks - pincer1.marks // [25] - [57] == [2] if (diff.size() == 1) { // it's a pincer def x = diff.first() // 2 def y = (pivot.marks - x).first() // 5 def z = (pincer1.marks - y).first() // 7 for (house2 in pivot.houses.findAll { ! (pincer1 in it) }) { // houses of pivot and not pincer1 for (pincer2 in house2.findAll { it.markCount == 2 && it != pivot && it != pincer1 && it.hasMark(x) && it.hasMark(z) && ! (it in house1) }) { pincer1.houses.flatten().intersect(pincer2.houses.flatten()).findAll { it != pivot && it != pincer1 && it != pincer2 }.each { madePlay = it.removeMark(z, this) || madePlay } if (madePlay) { return true } } } } } } } false } }