// checkHandicapCanonical func checkHandicapCanonical() { // Verify that the handicap patterns are preserved by transformaions, for i, brd := range brds { t := ah.BoardTrans(i) inv := ah.InverseTrans[t] fmt.Println("Checking", ah.TransName[i], "and its inverse:", ah.TransName[inv]) if brd != nil { newBrd := brd.TransBoard(t) newBrdInv := newBrd.TransBoard(inv) if differBrds(brd, newBrdInv) { printBrds("Error: inverse differs", brd, newBrdInv, ah.TransName[i]) } } else { fmt.Println("Error: brds [", i, "] has not been initialized.") } } }
// Test the transformation logic func ExampleTestTrans() { // Set up the test data boards. var col ah.ColSize var row ah.RowSize for size := 5; size <= 19; size += 2 { switch size { case 5: col = 5 row = 5 brd_5 = brd_5.InitAbstHier(col, row, ah.StringLevel, true) // ah.SetAHTrace(false) printInitBoard(brd_5, "Initial 5x5 Board") brd_5.PrintAbstHier("Initial 5x5 Board", true) SetUpTestBoard(size, brd_5, &test_5) brds[0] = brd_5 case 7: col = 7 row = 7 // brd_7 = new(ah.AbstHier) // brd_7.SetSize(col, row) brd_7 = brd_7.InitAbstHier(col, row, ah.StringLevel, true) printInitBoard2(brd_7) SetUpTestBoard(size, brd_7, &test_7) brds[1] = brd_7 case 9: col = 9 row = 9 // brd_9 = new(ah.AbstHier) // brd_9.SetSize(col, row) brd_9 = brd_9.InitAbstHier(col, row, ah.StringLevel, true) printInitBoard(brd_9, "Initial 9x9 Board") SetUpTestBoard(size, brd_9, &test_9) brds[2] = brd_9 case 11: col = 11 row = 11 // brd_11 = new(ah.AbstHier) // brd_11.SetSize(col, row) brd_11 = brd_11.InitAbstHier(col, row, ah.StringLevel, true) printInitBoard2(brd_11) SetUpTestBoard(size, brd_11, &test_11) brds[3] = brd_11 case 13: col = 13 row = 13 brd_13 = brd_13.InitAbstHier(col, row, ah.StringLevel, true) printInitBoard(brd_13, "Initial 13x13 Board") SetUpTestBoard(size, brd_13, &test_13) brds[4] = brd_13 case 15: col = 15 row = 15 brd_15 = brd_15.InitAbstHier(col, row, ah.StringLevel, true) printInitBoard2(brd_15) SetUpTestBoard(size, brd_15, &test_15) brds[5] = brd_15 case 17: col = 17 row = 17 brd_17 = brd_17.InitAbstHier(col, row, ah.StringLevel, true) printInitBoard(brd_17, "Initial 17x17 Board") SetUpTestBoard(size, brd_17, &test_17) brds[6] = brd_17 case 19: col = 19 row = 19 brd_19 = brd_19.InitAbstHier(col, row, ah.StringLevel, true) printInitBoard2(brd_19) SetUpTestBoard(size, brd_19, &test_19) brds[7] = brd_19 } } // Print each board, after applying one of the transformations, // and print it (for visual verification) // ah.SetAHTrace(true) // trace first one for i, brd := range brds { fmt.Println("Checking brds[", i, "]") if brd == nil { fmt.Println("Error in setup: brd == nil") } else { newBrd := brd.TransBoard(ah.BoardTrans(i)) printBrds("Visual Check", brd, newBrd, ah.TransName[i]) } ah.SetAHTrace(false) // turn off after first one } // Verify that the inverse transformations produce the original for i, brd := range brds { t := ah.BoardTrans(i) inv := ah.InverseTrans[t] fmt.Println("Checking", ah.TransName[i], "and its inverse:", ah.TransName[inv]) newBrd := brd.TransBoard(t) newBrdInv := newBrd.TransBoard(inv) if differBrds(brd, newBrdInv) { printBrds("Error: inverse differs", brd, newBrdInv, ah.TransName[i]) } } // Verify the transformation composition table nxtBrd := 0 // used to pick the next board for A := ah.T_FIRST; A <= ah.T_LAST; A++ { for B := ah.T_FIRST; B <= ah.T_LAST; B++ { C := ah.ComposeTrans[A][B] fmt.Println("Checking", ah.TransName[C], "=", ah.TransName[A], "*", ah.TransName[B]) brd := brds[nxtBrd] nxtBrd++ if nxtBrd >= 8 { nxtBrd = 0 } brdA := brd.TransBoard(A) brdAB := brdA.TransBoard(B) brdC := brd.TransBoard(C) if differBrds(brdAB, brdC) { printBrds("Error: "+ah.TransName[ah.ComposeTrans[A][B]], brdAB, brdC, "not equal"+ah.TransName[A]+"*"+ah.TransName[B]) } } } // Output: // Initial 5x5 Board Board 5 by 5 // ┏┯┯┯┓ // ┠╬┼╬┨ // ┠┼◘┼┨ // ┠╬┼╬┨ // ┗┷┷┷┛ // Abstraction Hierarchy: Initial 5x5 Board // Level 1 // Black nodes // Total 0 nodes, with 0 members // White nodes // Total 0 nodes, with 0 members // Unocc nodes // 0:202,3 1-mem:(E,5):202:202,adj:16(1),8(1), // 1:778,3 1-mem:(A,1):778:778,adj:4(1),2(1), // 2:906,3 3-mem:(D,1):906:906,(C,1),(B,1),adj:1(1),7(1),6(1),5(1),3(1), // 3:394,3 1-mem:(E,1):394:394,adj:2(1),8(1), // 4:842,3 3-mem:(A,4):842:842,(A,3),(A,2),adj:1(1),15(1),12(1),9(1),5(1), // 5:3018,3 1-mem:(B,2):3018:3018,adj:4(1),2(1),9(1),6(1), // 6:4042,3 1-mem:(C,2):4042:4042,adj:5(1),2(1),10(1),7(1), // 7:3018,3 1-mem:(D,2):3018:3018,adj:6(1),2(1),11(1),8(1), // 8:458,3 3-mem:(E,4):458:458,(E,3),(E,2),adj:0(1),7(1),3(1),14(1),11(1), // 9:4042,3 1-mem:(B,3):4042:4042,adj:4(1),5(1),12(1),10(1), // 10:1994,3 1-mem:(C,3):1994:1994,adj:9(1),6(1),13(1),11(1), // 11:4042,3 1-mem:(D,3):4042:4042,adj:8(1),10(1),7(1),14(1), // 12:3018,3 1-mem:(B,4):3018:3018,adj:4(1),9(1),16(1),13(1), // 13:4042,3 1-mem:(C,4):4042:4042,adj:12(1),10(1),16(1),14(1), // 14:3018,3 1-mem:(D,4):3018:3018,adj:8(1),13(1),11(1),16(1), // 15:586,3 1-mem:(A,5):586:586,adj:4(1),16(1), // 16:714,3 3-mem:(D,5):714:714,(C,5),(B,5),adj:0(1),14(1),13(1),15(1),12(1), // Total 17 nodes, with 25 members // Board 7 by 7 // ┏┯┯┯┯┯┓ // ┠╬┼┼┼╬┨ // ┠┼◘┼◘┼┨ // ┠┼┼╋┼┼┨ // ┠┼◘┼◘┼┨ // ┠╬┼┼┼╬┨ // ┗┷┷┷┷┷┛ // Initial 9x9 Board Board 9 by 9 // ┏┯┯┯┯┯┯┯┓ // ┠╬┼┼┼┼┼╬┨ // ┠┼◘┼┼┼◘┼┨ // ┠┼┼╬┼╬┼┼┨ // ┠┼┼┼◘┼┼┼┨ // ┠┼┼╬┼╬┼┼┨ // ┠┼◘┼┼┼◘┼┨ // ┠╬┼┼┼┼┼╬┨ // ┗┷┷┷┷┷┷┷┛ // Board 11 by 11 // ┏┯┯┯┯┯┯┯┯┯┓ // ┠╬┼┼┼┼┼┼┼╬┨ // ┠┼◘┼┼┼┼┼◘┼┨ // ┠┼┼╬┼┼┼╬┼┼┨ // ┠┼┼┼╬┼╬┼┼┼┨ // ┠┼┼┼┼◘┼┼┼┼┨ // ┠┼┼┼╬┼╬┼┼┼┨ // ┠┼┼╬┼┼┼╬┼┼┨ // ┠┼◘┼┼┼┼┼◘┼┨ // ┠╬┼┼┼┼┼┼┼╬┨ // ┗┷┷┷┷┷┷┷┷┷┛ // Initial 13x13 Board Board 13 by 13 // ┏┯┯┯┯┯┯┯┯┯┯┯┓ // ┠╬┼┼┼┼┼┼┼┼┼╬┨ // ┠┼╬┼┼┼┼┼┼┼╬┼┨ // ┠┼┼◘┼┼┼┼┼◘┼┼┨ // ┠┼┼┼╬┼┼┼╬┼┼┼┨ // ┠┼┼┼┼╬┼╬┼┼┼┼┨ // ┠┼┼┼┼┼◘┼┼┼┼┼┨ // ┠┼┼┼┼╬┼╬┼┼┼┼┨ // ┠┼┼┼╬┼┼┼╬┼┼┼┨ // ┠┼┼◘┼┼┼┼┼◘┼┼┨ // ┠┼╬┼┼┼┼┼┼┼╬┼┨ // ┠╬┼┼┼┼┼┼┼┼┼╬┨ // ┗┷┷┷┷┷┷┷┷┷┷┷┛ // Board 15 by 15 // ┏┯┯┯┯┯┯┯┯┯┯┯┯┯┓ // ┠╬┼┼┼┼┼┼┼┼┼┼┼╬┨ // ┠┼╬┼┼┼┼┼┼┼┼┼╬┼┨ // ┠┼┼◘┼┼┼◘┼┼┼◘┼┼┨ // ┠┼┼┼╬┼┼┼┼┼╬┼┼┼┨ // ┠┼┼┼┼╬┼┼┼╬┼┼┼┼┨ // ┠┼┼┼┼┼╬┼╬┼┼┼┼┼┨ // ┠┼┼◘┼┼┼◘┼┼┼◘┼┼┨ // ┠┼┼┼┼┼╬┼╬┼┼┼┼┼┨ // ┠┼┼┼┼╬┼┼┼╬┼┼┼┼┨ // ┠┼┼┼╬┼┼┼┼┼╬┼┼┼┨ // ┠┼┼◘┼┼┼◘┼┼┼◘┼┼┨ // ┠┼╬┼┼┼┼┼┼┼┼┼╬┼┨ // ┠╬┼┼┼┼┼┼┼┼┼┼┼╬┨ // ┗┷┷┷┷┷┷┷┷┷┷┷┷┷┛ // Initial 17x17 Board Board 17 by 17 // ┏┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┓ // ┠╬┼┼┼┼┼┼┼┼┼┼┼┼┼╬┨ // ┠┼╬┼┼┼┼┼┼┼┼┼┼┼╬┼┨ // ┠┼┼◘┼┼┼┼◘┼┼┼┼◘┼┼┨ // ┠┼┼┼╬┼┼┼┼┼┼┼╬┼┼┼┨ // ┠┼┼┼┼╬┼┼┼┼┼╬┼┼┼┼┨ // ┠┼┼┼┼┼╬┼┼┼╬┼┼┼┼┼┨ // ┠┼┼┼┼┼┼╋╋╋┼┼┼┼┼┼┨ // ┠┼┼◘┼┼┼╋◘╋┼┼┼◘┼┼┨ // ┠┼┼┼┼┼┼╋╋╋┼┼┼┼┼┼┨ // ┠┼┼┼┼┼╬┼┼┼╬┼┼┼┼┼┨ // ┠┼┼┼┼╬┼┼┼┼┼╬┼┼┼┼┨ // ┠┼┼┼╬┼┼┼┼┼┼┼╬┼┼┼┨ // ┠┼┼◘┼┼┼┼◘┼┼┼┼◘┼┼┨ // ┠┼╬┼┼┼┼┼┼┼┼┼┼┼╬┼┨ // ┠╬┼┼┼┼┼┼┼┼┼┼┼┼┼╬┨ // ┗┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┛ // Board 19 by 19 // ┏┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┓ // ┠╬┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼╬┨ // ┠┼╬┼┼┼┼┼┼┼┼┼┼┼┼┼╬┼┨ // ┠┼┼◘┼┼┼┼┼◘┼┼┼┼┼◘┼┼┨ // ┠┼┼┼╬┼┼┼┼┼┼┼┼┼╬┼┼┼┨ // ┠┼┼┼┼╬┼┼┼┼┼┼┼╬┼┼┼┼┨ // ┠┼┼┼┼┼╬┼┼┼┼┼╬┼┼┼┼┼┨ // ┠┼┼┼┼┼┼╋╋╋╋╋┼┼┼┼┼┼┨ // ┠┼┼┼┼┼┼╋╋╋╋╋┼┼┼┼┼┼┨ // ┠┼┼◘┼┼┼╋╋◘╋╋┼┼┼◘┼┼┨ // ┠┼┼┼┼┼┼╋╋╋╋╋┼┼┼┼┼┼┨ // ┠┼┼┼┼┼┼╋╋╋╋╋┼┼┼┼┼┼┨ // ┠┼┼┼┼┼╬┼┼┼┼┼╬┼┼┼┼┼┨ // ┠┼┼┼┼╬┼┼┼┼┼┼┼╬┼┼┼┼┨ // ┠┼┼┼╬┼┼┼┼┼┼┼┼┼╬┼┼┼┨ // ┠┼┼◘┼┼┼┼┼◘┼┼┼┼┼◘┼┼┨ // ┠┼╬┼┼┼┼┼┼┼┼┼┼┼┼┼╬┼┨ // ┠╬┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼╬┨ // ┗┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┛ // Checking brds[ 0 ] // Board size 5 by 5 after T_IDENTITY // 1.... | 1.... // 2..x. | 2..x. // 3.+.. | 3.+.. // 4.... | 4.... // 5.... | 5.... // Checking brds[ 1 ] // Board size 7 by 7 after T_ROTA_090 // 1...... | ....... // 2...... | ....... // 3.+.+.. | ..+x+.. // 4...x.. | ....... // 5.+.+.. | ..+.+.. // 6...... | ....... // 7...... | 1234567 // Checking brds[ 2 ] // Board size 9 by 9 after T_ROTA_180 // 1........ | ........9 // 2........ | ........8 // 3.+...+.. | ..+...+.7 // 4.....x.. | ........6 // 5........ | ........5 // 6........ | ..x.....4 // 7.+...+.. | ..+...+.3 // 8........ | ........2 // 9........ | ........1 // Checking brds[ 3 ] // Board size 11 by 11 after T_ROTA_270 // 1.......... | BA987654321 // 2.......... | ........... // 3.+.....+.. | ..+.....+.. // 4.......x.. | ........... // 5.......... | ........... // 6....+..... | .....+..... // 7.......... | ........... // 8.......... | ........... // 9.+.....+.. | ..+....x+.. // A.......... | ........... // B.......... | ........... // Checking brds[ 4 ] // Board size 13 by 13 after T_FLP_SLAS // 1............ | ............. // 2............ | ............. // 3............ | .........X... // 4..+.....+X.. | ...+.....+... // 5............ | ............. // 6............ | ............. // 7....+....... | ............. // 8............ | ......+...... // 9............ | ............. // A..+.....+... | ...+.....+... // B............ | ............. // C............ | ............. // D............ | DCBA987654321 // Checking brds[ 5 ] // Board size 15 by 15 after T_FLP_VERT // 1.............. | ..............1 // 2.............. | ..............2 // 3.............. | ..............3 // 4..+.......+X.. | ..X+.......+..4 // 5.............. | ..............5 // 6.............. | ..............6 // 7.............. | ..............7 // 8.....+........ | ........+.....8 // 9.............. | ..............9 // A.............. | ..............A // B.............. | ..............B // C..+.......+... | ...+.......+..C // D.............. | ..............D // E.............. | ..............E // F.............. | ..............F // Checking brds[ 6 ] // Board size 17 by 17 after T_FLP_BACK // 1................ | 123456789ABCDEFGH // 2................ | ................. // 3................ | ................. // 4..+.........+X.. | ...+.........+... // 5................ | ................. // 6................ | ................. // 7................ | ................. // 8................ | ........+........ // 9......+......... | ................. // A................ | ................. // B................ | ................. // C................ | ................. // D................ | ................. // E..+.........+... | ...+.........+... // F................ | ...X............. // G................ | ................. // H................ | ................. // Checking brds[ 7 ] // Board size 19 by 19 after T_FLP_HORI // 1.................. | J.................. // 2.................. | I.................. // 3.................. | H.................. // 4..+.....+.....+X.. | G..+.....+.....+... // 5.................. | F.................. // 6.................. | E.................. // 7.................. | D.................. // 8.................. | C.................. // 9.................. | B.................. // A..+.....+.....+... | A..+.....+.....+... // B.................. | 9.................. // C.................. | 8.................. // D.................. | 7.................. // E.................. | 6.................. // F.................. | 5.................. // G..+.....+.....+... | 4..+.....+.....+X.. // H.................. | 3.................. // I.................. | 2.................. // J.................. | 1.................. // Checking T_IDENTITY and its inverse: T_IDENTITY // Checking T_ROTA_090 and its inverse: T_ROTA_270 // Checking T_ROTA_180 and its inverse: T_ROTA_180 // Checking T_ROTA_270 and its inverse: T_ROTA_090 // Checking T_FLP_SLAS and its inverse: T_FLP_SLAS // Checking T_FLP_VERT and its inverse: T_FLP_VERT // Checking T_FLP_BACK and its inverse: T_FLP_BACK // Checking T_FLP_HORI and its inverse: T_FLP_HORI // Checking T_IDENTITY = T_IDENTITY * T_IDENTITY // Checking T_ROTA_090 = T_IDENTITY * T_ROTA_090 // Checking T_ROTA_180 = T_IDENTITY * T_ROTA_180 // Checking T_ROTA_270 = T_IDENTITY * T_ROTA_270 // Checking T_FLP_SLAS = T_IDENTITY * T_FLP_SLAS // Checking T_FLP_VERT = T_IDENTITY * T_FLP_VERT // Checking T_FLP_BACK = T_IDENTITY * T_FLP_BACK // Checking T_FLP_HORI = T_IDENTITY * T_FLP_HORI // Checking T_ROTA_090 = T_ROTA_090 * T_IDENTITY // Checking T_ROTA_180 = T_ROTA_090 * T_ROTA_090 // Checking T_ROTA_270 = T_ROTA_090 * T_ROTA_180 // Checking T_IDENTITY = T_ROTA_090 * T_ROTA_270 // Checking T_FLP_HORI = T_ROTA_090 * T_FLP_SLAS // Checking T_FLP_SLAS = T_ROTA_090 * T_FLP_VERT // Checking T_FLP_VERT = T_ROTA_090 * T_FLP_BACK // Checking T_FLP_BACK = T_ROTA_090 * T_FLP_HORI // Checking T_ROTA_180 = T_ROTA_180 * T_IDENTITY // Checking T_ROTA_270 = T_ROTA_180 * T_ROTA_090 // Checking T_IDENTITY = T_ROTA_180 * T_ROTA_180 // Checking T_ROTA_090 = T_ROTA_180 * T_ROTA_270 // Checking T_FLP_BACK = T_ROTA_180 * T_FLP_SLAS // Checking T_FLP_HORI = T_ROTA_180 * T_FLP_VERT // Checking T_FLP_SLAS = T_ROTA_180 * T_FLP_BACK // Checking T_FLP_VERT = T_ROTA_180 * T_FLP_HORI // Checking T_ROTA_270 = T_ROTA_270 * T_IDENTITY // Checking T_IDENTITY = T_ROTA_270 * T_ROTA_090 // Checking T_ROTA_090 = T_ROTA_270 * T_ROTA_180 // Checking T_ROTA_180 = T_ROTA_270 * T_ROTA_270 // Checking T_FLP_VERT = T_ROTA_270 * T_FLP_SLAS // Checking T_FLP_BACK = T_ROTA_270 * T_FLP_VERT // Checking T_FLP_HORI = T_ROTA_270 * T_FLP_BACK // Checking T_FLP_SLAS = T_ROTA_270 * T_FLP_HORI // Checking T_FLP_SLAS = T_FLP_SLAS * T_IDENTITY // Checking T_FLP_VERT = T_FLP_SLAS * T_ROTA_090 // Checking T_FLP_BACK = T_FLP_SLAS * T_ROTA_180 // Checking T_FLP_HORI = T_FLP_SLAS * T_ROTA_270 // Checking T_IDENTITY = T_FLP_SLAS * T_FLP_SLAS // Checking T_ROTA_090 = T_FLP_SLAS * T_FLP_VERT // Checking T_ROTA_180 = T_FLP_SLAS * T_FLP_BACK // Checking T_ROTA_270 = T_FLP_SLAS * T_FLP_HORI // Checking T_FLP_VERT = T_FLP_VERT * T_IDENTITY // Checking T_FLP_BACK = T_FLP_VERT * T_ROTA_090 // Checking T_FLP_HORI = T_FLP_VERT * T_ROTA_180 // Checking T_FLP_SLAS = T_FLP_VERT * T_ROTA_270 // Checking T_ROTA_270 = T_FLP_VERT * T_FLP_SLAS // Checking T_IDENTITY = T_FLP_VERT * T_FLP_VERT // Checking T_ROTA_090 = T_FLP_VERT * T_FLP_BACK // Checking T_ROTA_180 = T_FLP_VERT * T_FLP_HORI // Checking T_FLP_BACK = T_FLP_BACK * T_IDENTITY // Checking T_FLP_HORI = T_FLP_BACK * T_ROTA_090 // Checking T_FLP_SLAS = T_FLP_BACK * T_ROTA_180 // Checking T_FLP_VERT = T_FLP_BACK * T_ROTA_270 // Checking T_ROTA_180 = T_FLP_BACK * T_FLP_SLAS // Checking T_ROTA_270 = T_FLP_BACK * T_FLP_VERT // Checking T_IDENTITY = T_FLP_BACK * T_FLP_BACK // Checking T_ROTA_090 = T_FLP_BACK * T_FLP_HORI // Checking T_FLP_HORI = T_FLP_HORI * T_IDENTITY // Checking T_FLP_SLAS = T_FLP_HORI * T_ROTA_090 // Checking T_FLP_VERT = T_FLP_HORI * T_ROTA_180 // Checking T_FLP_BACK = T_FLP_HORI * T_ROTA_270 // Checking T_ROTA_090 = T_FLP_HORI * T_FLP_SLAS // Checking T_ROTA_180 = T_FLP_HORI * T_FLP_VERT // Checking T_ROTA_270 = T_FLP_HORI * T_FLP_BACK // Checking T_IDENTITY = T_FLP_HORI * T_FLP_HORI }