//SUDOKU //todo: make paste work //make options for which solving methods to use? //insults //speed solve //fill one every minute since started using System; using System.Collections; using System.Threading; using System.Windows.Forms; using System.Drawing; namespace sudoku { public class PuzzleGrid : System.Windows.Forms.Form { #region DefineComponents private System.Windows.Forms.RichTextBox cell01; private System.Windows.Forms.RichTextBox cell02; private System.Windows.Forms.RichTextBox cell03; private System.Windows.Forms.RichTextBox cell04; private System.Windows.Forms.RichTextBox cell05; private System.Windows.Forms.RichTextBox cell06; private System.Windows.Forms.RichTextBox cell07; private System.Windows.Forms.RichTextBox cell08; private System.Windows.Forms.RichTextBox cell09; private System.Windows.Forms.RichTextBox cell10; private System.Windows.Forms.RichTextBox cell11; private System.Windows.Forms.RichTextBox cell12; private System.Windows.Forms.RichTextBox cell13; private System.Windows.Forms.RichTextBox cell14; private System.Windows.Forms.RichTextBox cell15; private System.Windows.Forms.RichTextBox cell16; private System.Windows.Forms.RichTextBox cell17; private System.Windows.Forms.RichTextBox cell18; private System.Windows.Forms.RichTextBox cell19; private System.Windows.Forms.RichTextBox cell20; private System.Windows.Forms.RichTextBox cell21; private System.Windows.Forms.RichTextBox cell22; private System.Windows.Forms.RichTextBox cell23; private System.Windows.Forms.RichTextBox cell24; private System.Windows.Forms.RichTextBox cell25; private System.Windows.Forms.RichTextBox cell26; private System.Windows.Forms.RichTextBox cell27; private System.Windows.Forms.RichTextBox cell28; private System.Windows.Forms.RichTextBox cell29; private System.Windows.Forms.RichTextBox cell30; private System.Windows.Forms.RichTextBox cell31; private System.Windows.Forms.RichTextBox cell32; private System.Windows.Forms.RichTextBox cell33; private System.Windows.Forms.RichTextBox cell34; private System.Windows.Forms.RichTextBox cell35; private System.Windows.Forms.RichTextBox cell36; private System.Windows.Forms.RichTextBox cell37; private System.Windows.Forms.RichTextBox cell38; private System.Windows.Forms.RichTextBox cell39; private System.Windows.Forms.RichTextBox cell40; private System.Windows.Forms.RichTextBox cell41; private System.Windows.Forms.RichTextBox cell42; private System.Windows.Forms.RichTextBox cell43; private System.Windows.Forms.RichTextBox cell44; private System.Windows.Forms.RichTextBox cell45; private System.Windows.Forms.RichTextBox cell46; private System.Windows.Forms.RichTextBox cell47; private System.Windows.Forms.RichTextBox cell48; private System.Windows.Forms.RichTextBox cell49; private System.Windows.Forms.RichTextBox cell50; private System.Windows.Forms.RichTextBox cell51; private System.Windows.Forms.RichTextBox cell52; private System.Windows.Forms.RichTextBox cell53; private System.Windows.Forms.RichTextBox cell54; private System.Windows.Forms.RichTextBox cell55; private System.Windows.Forms.RichTextBox cell56; private System.Windows.Forms.RichTextBox cell57; private System.Windows.Forms.RichTextBox cell58; private System.Windows.Forms.RichTextBox cell59; private System.Windows.Forms.RichTextBox cell60; private System.Windows.Forms.RichTextBox cell61; private System.Windows.Forms.RichTextBox cell62; private System.Windows.Forms.RichTextBox cell63; private System.Windows.Forms.RichTextBox cell64; private System.Windows.Forms.RichTextBox cell65; private System.Windows.Forms.RichTextBox cell66; private System.Windows.Forms.RichTextBox cell67; private System.Windows.Forms.RichTextBox cell68; private System.Windows.Forms.RichTextBox cell69; private System.Windows.Forms.RichTextBox cell70; private System.Windows.Forms.RichTextBox cell71; private System.Windows.Forms.RichTextBox cell72; private System.Windows.Forms.RichTextBox cell73; private System.Windows.Forms.RichTextBox cell74; private System.Windows.Forms.RichTextBox cell75; private System.Windows.Forms.RichTextBox cell76; private System.Windows.Forms.RichTextBox cell77; private System.Windows.Forms.RichTextBox cell78; private System.Windows.Forms.RichTextBox cell79; private System.Windows.Forms.RichTextBox cell80; private System.Windows.Forms.RichTextBox cell81; private System.Windows.Forms.MenuItem menuItem44; private System.Windows.Forms.MenuItem menuItem43; private System.Windows.Forms.MenuItem menuItem42; private System.Windows.Forms.MenuItem menuItem41; private System.Windows.Forms.MenuItem menuItem40; private System.Windows.Forms.MenuItem menuItem18; private System.Windows.Forms.MenuItem menuItem22; private System.Windows.Forms.MenuItem menuItem12; private System.Windows.Forms.MenuItem menuItem13; private System.Windows.Forms.MenuItem menuItem10; private System.Windows.Forms.MenuItem menuItem49; private System.Windows.Forms.MenuItem menuItem48; private System.Windows.Forms.MenuItem menuItem17; private System.Windows.Forms.MenuItem menuItem14; private System.Windows.Forms.MenuItem menuItem15; private System.Windows.Forms.Button StepButton; private System.Windows.Forms.Button resetButton; private System.Windows.Forms.MenuItem menuItem19; private System.Windows.Forms.MenuItem menuItem20; private System.Windows.Forms.MenuItem menuItem23; private System.Windows.Forms.MenuItem menuItem9; private System.Windows.Forms.MenuItem menuItem25; private System.Windows.Forms.MenuItem menuItem24; private System.Windows.Forms.MenuItem menuItem27; private System.Windows.Forms.MenuItem menuItem26; private System.Windows.Forms.MenuItem menuItem29; private System.Windows.Forms.MenuItem menuItem28; private System.Windows.Forms.MenuItem menuItem56; private System.Windows.Forms.MenuItem menuItem57; private System.Windows.Forms.MenuItem menuItem54; private System.Windows.Forms.MenuItem menuItem55; private System.Windows.Forms.MenuItem menuItem52; private System.Windows.Forms.MenuItem menuItem53; private System.Windows.Forms.MenuItem menuItem50; private System.Windows.Forms.MenuItem menuItem51; private System.Windows.Forms.MenuItem menuItem58; private System.Windows.Forms.MenuItem menuItem59; private System.Windows.Forms.Label FoundLabel; private System.Windows.Forms.MenuItem menuItem30; private System.Windows.Forms.MenuItem menuItem31; private System.Windows.Forms.MenuItem menuItem32; private System.Windows.Forms.MenuItem menuItem33; private System.Windows.Forms.MenuItem menuItem34; private System.Windows.Forms.MenuItem menuItem35; private System.Windows.Forms.MenuItem menuItem36; private System.Windows.Forms.MenuItem menuItem37; private System.Windows.Forms.MenuItem menuItem38; private System.Windows.Forms.MenuItem menuItem39; private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.Label LookingInLabel; private System.Windows.Forms.MenuItem menuItem21; private System.Windows.Forms.Button NewButton; private System.Windows.Forms.Panel panel1; private System.Windows.Forms.Button FindButton; private System.Windows.Forms.Button SolveButton; private System.Windows.Forms.Label StatusLabel; private System.Windows.Forms.Button ClearButton; private System.Windows.Forms.MenuItem menuItem16; private System.Windows.Forms.MenuItem menuItem3; private System.Windows.Forms.MenuItem menuItem2; private System.Windows.Forms.MenuItem menuItem1; private System.Windows.Forms.MenuItem menuItem0; private System.Windows.Forms.MenuItem menuItem7; private System.Windows.Forms.MenuItem menuItem6; private System.Windows.Forms.MenuItem menuItem5; private System.Windows.Forms.MenuItem menuItem4; private System.Windows.Forms.Button TestButton; private System.Windows.Forms.MainMenu mainMenu1; private System.Windows.Forms.MenuItem menuItem8; private System.Windows.Forms.MenuItem menuItem45; private System.Windows.Forms.Label SearchingForLabel; private System.Windows.Forms.MenuItem menuItem47; private System.Windows.Forms.MenuItem menuItem46; private System.Windows.Forms.MenuItem menuItem11; #endregion [STAThread] public static void Main(string[] args) { Application.Run(new PuzzleGrid()); } //constructor public PuzzleGrid( ) { #region Initialize solv, startSolv, cells, puzzleList for (int n=0; n<=80; n++) { for (int i=0; i<=8; i++) { this.solv[n,i] = 1; this.startSolv[n,i] = 1; } } //add some puzzles string[] puzzles = {"400000805030000000000700000020000060000080400000010000000603070500200000104000000", "008100705754098013001506908400800091010059830080001002100687000800025100507014080", "000706004008030006005000020120400060009000400040008097070000200300010600800603000", "000008010050000003020460009003000007000302000800000100600071080100000070090500000", "060700000200080300508006004000040089000050000730060000100300908004010002000008010", "070800000008009000034070600190002004000040000200600031003090240000500700000006090", "000000602000003040000480390014800000500030001000002730087041000090300000601000000", "000140300053006080009000001000009024000010000480700000300000800060200930001083000", "016300000700008100000540000069000007001020800800000410000087000003600001000005280", "520006000000000701300000000000400800600000050000000000041800000000030020008700000", "600000803040700000000000000000504070300200000106000000020000050000080600000010000", "000000520080400000030009000501000600200700000000300000600010000000000704000000030", "390170084000300000008000700500030002040607050006050900001000400000700000970810023", "002000050086300700003071008010090020000000000004080300700120600009006870040000200", "002005100800010005061030920000200000009080200010009070027090530100020007004500800", "000504000960030014080002070306000007050000090800000302010300040730040089000108000", "405080006000000040000200853000700500200509007001003000659002000010000000700010904", "710080095000746000030000070040070030270194058050020010080000060000465000560010049", "000000000000942080160000029000000008906000001400250000004000000020008090050000700", "052470000060000000000008010400000009700950000020040030000800090000003706000091000", "090000000001006000060080070300000010000039000000050002170400028000003000086000057", "500068000000000060042050000000800900001000040903000620700001009004200003080000000", "070021004000030000601000002000000060008600703190000040010000208420900000000000000", "000000001007050309004800020000000000030005700009420000000003000001000407060278000", "000006003009040005320000008000010000001750609200000080000060000000800040470000200", "002046000004080005070030009000002000305700000700000400006000093000054078000000000", "020000000000004800054018030700001004000086050000000600000000100000020009230400005", "009043000000000030410070000000000000800500060040006002000000010004098006700600520", "000000000406070090050038200000000030900000000004260000070003002001600800085000700", "000604000000000003010002600002000000600090015804000006000007000976050000000203100", "000040000050000009003078400001000000620000000000503800000020000006400703405100020", "020007005000000000600095001070004130000000200001050006700010800080070000000200049", "000500003000820001300001790170000000000000300600712040040060000090000000060050200", "080400000130000000000000008400001000507002003000900100000020780200006030076003009", "050000000006005091009000380400000008000038002073000000000010000280470500600000070", "010060900009005000030000076001030002720000040008000000007300009305007600000000020", "000000000070006208100000054003050000000300002200800006900000080300070000007025401", "000600004450000200000089300970000003063000000004002700609050000000000000500003061", "030010000000042703020906040500020000349000000000000001000009000006000080005003460", "000060000050000970002005000000200080074000000085040201001007000600004000920600100", "000000000900100002004028000650000700001000003009702000000005070040000061035010900", "000002000013409002709000015000005000100080006060970080500006000002000000000200030", "000000000000805049200060301009000000000021038000300000005000000006004800130009602", "000002073080000000005700200900000010800000004600815090000000460400000502000096000", "000000000000067000007080012000000000030006500501000893070000000009001024004390008", "000000010020000930065030000940050000007800200600000000001200004000609800000000127", "501083007000720000000000010008000020010050900003000001000900080040007500390400000", "005001080040000009007659010000000070004200000010000806000035000000000090970000108", "007000030050009001900000000020000000500030029080074103000408000002000006000015800", "000050000000000040003601008000000701020010800070009000400003000000006590059007206", "000100000098020006300040050500000003061000000000700860007080300000000009005200408", "003000000000028500200000070000002004010000023630001057100004080050000900090700000", "060000000040700080000006130100400005000020800050000076000200300800040020790008000", "000000050000000021039000000400051007017004900000360500000015000900000160640000000", "300007501708006000000800003800004790090000000000023000962000007000000060000040900", "170000036000090040306000080600008201200005000000010000800007000050000000000051063", "000000000700040000090006120400010007000020500501098000000001060000060280000405300", "740060030002005000018002009080020600900000070004080000003700000600090000020004000", "900060000000030000030800406005000000009080300004000297020000004000300000680200015", "053670009000000050000020016000003702900000060000500000020010005106000090000900040", "000001850002008031300500400641000000900005000000000080000906000000000000509040072", "001000080000004500005070000002730000000000200358010000203056000900000001006090700", "040000000012000000008200537000000200300080004005307000000040060900000070200790001", "260070038000010070000004602010005000090230400000007200000000000700000080001008700", "001020000080005090060400100000080030000042050097000000000000000070000040032017605", "000003001040000830005040000064100080010007000000300007509000060000030050000870003", "028005000400100000000003000000400850000200000100070003700090040980500006560002000", "000000500300000000090018000100900260060000400980100000070300000000020316040800005", "000000000000109620060007059001000000090804002000000346008000001906003000000000580", "000002400500000908020065070080030001074000000060000009000004005000000030012007800", "000091000000200870000600100000050000000060003007900216500000020280030500003007000", "000060059084010300000007000008000000000300001500400900400000000050780240097000003", "080000003600000907000050060000090000000403600159002000000008090020001040003500008", "007006000000000104040203009408000006900810000000009000000000030001035080200008500", "004300807800002030030006000006905002090070040000000000000000506000000000389050070", "004200700200060000000300100005007009080600007409001080000000000610052040000000008", "001000050036050009007900006000000030600801000000060105000000000598020000020073000", "700000003008030200000007000000900407900460500360800000030500000001000020800009100", "000001000108040500060090400000009000009700001400100230000000000057406000800000302", "090040200000000003506900000000000150073000400002400076020001000000090700005070040", "708900000006008040000250030000000100600010020070005060000070000920003000100080600", "008607000070005410900000000000000002040200080007003500000000609000050700052090004", "000900040081000005004052000000609300070000800200000004000000001603000900000106028", "700006050060000040000700080040000000100300000003002400000073092008060000602001300", "000002005060500800009100030752000000000380000000700000038000001000004003420008600", "070000005000020900530000700009240000028509000000000001040010007001000043700300000", "002040000680051000700000080000030005000000900205900701000009078000006090006300000", "050300000000080490800900060970000200000000017406000080008000000000030100094000670", "007600001400000000000804092090000050680072000002009030000000506005023800000000000", "003250000000008500000700008000000069302040000768000100000000000800000004500821030", "000000000000800037098001200000000006065000900800405300004000002000080000072056100", "000640050040000000500008000000081300003050008100002005700000000005400036082005000", "001009006000002300009603024000000000058000009600700001000000000040030700160000508", "200000080000400000000900746060205004000300070040076020003010000600008000010000002", "074081000000056090000400030000900001007005300006000000000020000030000217000890006", "007018009004005001000000500921700008800500000000409000008000007609000000000000280", "000040000300000062001200030000000520008674000000800640000001800009000010060709000", "002007000010000030008006004004000062300082007000560300000405000000000270801700000", "000000000305040002000260008010000000000400905070306201700000000200018400600500080", "000000000000140060007059031000000007030400500802000009016904000040207006000000008", "053006170000000000060098002200001004040800309000000000001000060009700800020000901", "004080000050000264910000000007000000300000057000054010000000001200500603090043800", "000006030000010802700300950010600300005200094038900000100000005080000000000005400", "000305000007091008000000300480000001000083500092000400000000130001000004040009025", "000004070000020100800060902026000000000030807050001000003070010600892003080000000", "000080000100000090029130006000000000578900010002360000000004000010005930400600200", "006090000000008052740000080000000000000900561203001470000000000008040635000079000", "000000001100050080090100704070080000000049000030000479009036000001008000020004006", "000000004100004000020070600092600400000039000007050002903000020000900040510700800", "000000000340500200090314000000000000000071094004600500600000002017008060030007800", "000000090063002080000460700010900065050000008908000000807000040005100000090704000", "700000000140900020000584600000030008000000040093000000800000100210048300007001006", "960140008045000900000020030000082000050006000400790250000000403004000009010000000", "000000000904800600000714002020060005300000200608107000000000100043000050001030060", "000000000400870015030000820009030000080000060200150003000060007007085009300000200", "000004089900000060000090000400200000050030720807000040002000008790300000008010406", "000000080300097600000803900000500000000000030009048205071000002000400000635000047", "000000007300000008700006300000000004006027080080005921051070000060002030000008005", "008000000601803000420050000000000820006208790004000010000000003700004000059307000", "320000000000008609000054002000000308000400020085000094501006000000030000462090000", "006900000107050300000000050000004003080003072001007000805076400060000100009100000", "000000000001002003350000806000003007000108000000040539098000020005300000200609040", "000000085081040000037001004000013000000400000020060700000600040090007001003000652", "000638000300001000000005080020007000080500470040000020000090040090700010004010260", "000200405000060300060008000010050000004832709030600002000000020000003500708000003", "000000000045009020002004601000200040400010000090005007020000010500700460008060090", "007060000050200600060000102003080004800005000001000203002003041000000000010750800", "004056000305800090000000060040910086000002000020705030000000010080100004000004002", "000000000003006805040080900030070000004010070080900300008400007070830200000091000", "000003040070090000438005000000502010002700000040000008009030820003040060000007003", "000000000030600000004028910000000000000497000820001470000000000600239001300000846", "060005300500400080001900000000007000090004057058000160004003090000050070900000008", "000000000000070050516028040000000000603000007089052001008000090900600800760010000", "000000400094200050000050070470010000050000030001009500000000200026700100700080940", "000000090000690050520700000000030009080205300040080006300046005001000000200300400", "400701000750003008200000000005100003000060050380005047000004001000010802000000030", "000000000010000047000056302000000000020010030700642001000000010073025080500030004", "000000050001004600900070008000007009710045000400080000000209007040010060070000102", "700300209080010003002006500028000000050004100000100000000580000000009002603002010", "600000003090000000052006040020700000000005106079030000904003052000900030001000008", "000018000010630000000000089709006200002000005800050300000093040600000030001400050", "000008000003670000000910760000040890008003050000090070000000000310500000045209001", "600000000005370090000010007000002040140050000083000900006090000000000320930480005", "021009000007010060000800310000000530010095840070008000000030000009400100060020000", "098000007070080020000300500200000000030070000065000900000000004607003008900046250", "000000000000863020091200080000000000027000000014000807000090003000005010009324065", "079000010030005607000009000000000000080500002510006040020800000000071400000290035", "000006000003000072521090000000007008098000000700000426004603700060800500010000000", "050923000700000000920000105000000000035400010604005309000008000000000270308010000", "200100630004000000050036000007840000080900007100000040000005000008009703005080100", "106000000030040010087020050000031029070000800000004301000000000918000000200050008", "490002000003000100000716000000200600008600010000000390900003200000490000050100470", "000000004690000057008000200000000000200000080040391700050000000003020045702065300", "200700006007005800000016003000408000100620000900037000050000000300000020090300108", "000059400200010070006380009002030000000008000605000020300490000500020380000000004", "087000129002040000030000000000000091003000000020750004004017030050000000000409702", "007000000100000000836500074010000057020000103050009000500060000000104000000050268", "000074081000030046000800000050019000008300600900507000002000090060000000149000200", "005014000010070000008009600100053009020000070906001000069020000800000090000007008", "000005000046000705100036000050200040001300000030408000000904002080000000000027906", "000080300602000000501000800000004100000896004400000006007050200006000090804071000", "090000002500402006000000518006900000000017009000045020900080005003000000010309000", "000000917054000030000800000800000003002030690000410002000070020100000000467009008", "900000080000036000100000200000048700001602048300070000069000000000200670780000004", "000000000070120030900000876000000000058013002003900700004000020200030080600097000", "000300076080090000020000150039014600006000080004020000000070005350000060000450000", "007903100000006000500720009000000032000007500400000010046500000800100005903000060", "008900000365008001000010000800741060000050107030000000040000090900000023002000005", "000000000342015009809043006000000000008400000000087134000000000590700000010000270", "000007000000309126000002400050000000006010005037000904000005070090040018002000300", "406000000000004000051039000190007004000002700003045962000000020040000000900800500", "000000002670980000000001570000008000004300000006200039000000000900064100300107420", "000020600001000000000650090090700130000594000080031540000000480045000000206000000", "010090002800000000500030006003040700004070000000502008000027060008109003000000019", "000000000600050040000840290008000002190000000005008901000036000007200100010000825"}; puzzleList.AddRange(puzzles); cell01 = new System.Windows.Forms.RichTextBox(); cell02 = new System.Windows.Forms.RichTextBox(); cell03 = new System.Windows.Forms.RichTextBox(); cell04 = new System.Windows.Forms.RichTextBox(); cell05 = new System.Windows.Forms.RichTextBox(); cell06 = new System.Windows.Forms.RichTextBox(); cell07 = new System.Windows.Forms.RichTextBox(); cell08 = new System.Windows.Forms.RichTextBox(); cell09 = new System.Windows.Forms.RichTextBox(); cell10 = new System.Windows.Forms.RichTextBox(); cell11 = new System.Windows.Forms.RichTextBox(); cell12 = new System.Windows.Forms.RichTextBox(); cell13 = new System.Windows.Forms.RichTextBox(); cell14 = new System.Windows.Forms.RichTextBox(); cell15 = new System.Windows.Forms.RichTextBox(); cell16 = new System.Windows.Forms.RichTextBox(); cell17 = new System.Windows.Forms.RichTextBox(); cell18 = new System.Windows.Forms.RichTextBox(); cell19 = new System.Windows.Forms.RichTextBox(); cell20 = new System.Windows.Forms.RichTextBox(); cell21 = new System.Windows.Forms.RichTextBox(); cell22 = new System.Windows.Forms.RichTextBox(); cell23 = new System.Windows.Forms.RichTextBox(); cell24 = new System.Windows.Forms.RichTextBox(); cell25 = new System.Windows.Forms.RichTextBox(); cell26 = new System.Windows.Forms.RichTextBox(); cell27 = new System.Windows.Forms.RichTextBox(); cell28 = new System.Windows.Forms.RichTextBox(); cell29 = new System.Windows.Forms.RichTextBox(); cell30 = new System.Windows.Forms.RichTextBox(); cell31 = new System.Windows.Forms.RichTextBox(); cell32 = new System.Windows.Forms.RichTextBox(); cell33 = new System.Windows.Forms.RichTextBox(); cell34 = new System.Windows.Forms.RichTextBox(); cell35 = new System.Windows.Forms.RichTextBox(); cell36 = new System.Windows.Forms.RichTextBox(); cell37 = new System.Windows.Forms.RichTextBox(); cell38 = new System.Windows.Forms.RichTextBox(); cell39 = new System.Windows.Forms.RichTextBox(); cell40 = new System.Windows.Forms.RichTextBox(); cell41 = new System.Windows.Forms.RichTextBox(); cell42 = new System.Windows.Forms.RichTextBox(); cell43 = new System.Windows.Forms.RichTextBox(); cell44 = new System.Windows.Forms.RichTextBox(); cell45 = new System.Windows.Forms.RichTextBox(); cell46 = new System.Windows.Forms.RichTextBox(); cell47 = new System.Windows.Forms.RichTextBox(); cell48 = new System.Windows.Forms.RichTextBox(); cell49 = new System.Windows.Forms.RichTextBox(); cell50 = new System.Windows.Forms.RichTextBox(); cell51 = new System.Windows.Forms.RichTextBox(); cell52 = new System.Windows.Forms.RichTextBox(); cell53 = new System.Windows.Forms.RichTextBox(); cell54 = new System.Windows.Forms.RichTextBox(); cell55 = new System.Windows.Forms.RichTextBox(); cell56 = new System.Windows.Forms.RichTextBox(); cell57 = new System.Windows.Forms.RichTextBox(); cell58 = new System.Windows.Forms.RichTextBox(); cell59 = new System.Windows.Forms.RichTextBox(); cell60 = new System.Windows.Forms.RichTextBox(); cell61 = new System.Windows.Forms.RichTextBox(); cell62 = new System.Windows.Forms.RichTextBox(); cell63 = new System.Windows.Forms.RichTextBox(); cell64 = new System.Windows.Forms.RichTextBox(); cell65 = new System.Windows.Forms.RichTextBox(); cell66 = new System.Windows.Forms.RichTextBox(); cell67 = new System.Windows.Forms.RichTextBox(); cell68 = new System.Windows.Forms.RichTextBox(); cell69 = new System.Windows.Forms.RichTextBox(); cell70 = new System.Windows.Forms.RichTextBox(); cell71 = new System.Windows.Forms.RichTextBox(); cell72 = new System.Windows.Forms.RichTextBox(); cell73 = new System.Windows.Forms.RichTextBox(); cell74 = new System.Windows.Forms.RichTextBox(); cell75 = new System.Windows.Forms.RichTextBox(); cell76 = new System.Windows.Forms.RichTextBox(); cell77 = new System.Windows.Forms.RichTextBox(); cell78 = new System.Windows.Forms.RichTextBox(); cell79 = new System.Windows.Forms.RichTextBox(); cell80 = new System.Windows.Forms.RichTextBox(); cell81 = new System.Windows.Forms.RichTextBox(); InitializeComponent(); FoundLabel.Text = "0 Found"; System.Windows.Forms.RichTextBox[] cells2 = { this.cell01, this.cell02, this.cell03, this.cell04, this.cell05, this.cell06, this.cell07, this.cell08, this.cell09, this.cell10, this.cell11, this.cell12, this.cell13, this.cell14, this.cell15, this.cell16, this.cell17, this.cell18, this.cell19, this.cell20, this.cell21, this.cell22, this.cell23, this.cell24, this.cell25, this.cell26, this.cell27, this.cell28, this.cell29, this.cell30, this.cell31, this.cell32, this.cell33, this.cell34, this.cell35, this.cell36, this.cell37, this.cell38, this.cell39, this.cell40, this.cell41, this.cell42, this.cell43, this.cell44, this.cell45, this.cell46, this.cell47, this.cell48, this.cell49, this.cell50, this.cell51, this.cell52, this.cell53, this.cell54, this.cell55, this.cell56, this.cell57, this.cell58, this.cell59, this.cell60, this.cell61, this.cell62, this.cell63, this.cell64, this.cell65, this.cell66, this.cell67, this.cell68, this.cell69, this.cell70, this.cell71, this.cell72, this.cell73, this.cell74, this.cell75, this.cell76, this.cell77, this.cell78, this.cell79, this.cell80, this.cell81}; this.thecells = cells2; int cellrow = 0; int cellcol = 0; for (int irtb = 0; irtb < 81; irtb++) { this.thecells[irtb].BackColor = normColor; this.thecells[irtb].DetectUrls = false; this.thecells[irtb].Font = new System.Drawing.Font("Courier New", 6.65F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.thecells[irtb].ForeColor = this.possColor; this.thecells[irtb].MaxLength = 1; this.thecells[irtb].ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.None; this.thecells[irtb].Size = new System.Drawing.Size(40, 40); this.thecells[irtb].Text = " 1 2 3\n 4 5 6\n 7 8 9"; this.thecells[irtb].WordWrap = false; this.thecells[irtb].Leave += new System.EventHandler(this.CellLeave); this.thecells[irtb].TextChanged += new System.EventHandler(this.CellTextChanged); this.thecells[irtb].Enter += new System.EventHandler(this.CellEnter); cellToRC( irtb, ref cellrow, ref cellcol ); //40 for each cell before it, plus four for the original offset of the top left corner, plus 4 for each set of three (box) behind it this.thecells[irtb].Location = new System.Drawing.Point( 40 * cellcol + 4 * (int)Math.Floor(cellcol / 3) + 4, 40 * cellrow + 4 * (int)Math.Floor(cellrow / 3) + 4 ); this.thecells[irtb].Name = "cell" + (irtb < 10 ? "0" : "") + (irtb + 1).ToString(); this.thecells[irtb].TabIndex = irtb + 1; this.panel1.Controls.Add(this.thecells[irtb]); } #endregion } #region Events void CellTextChanged(object sender, System.EventArgs e) { //if nothing should be done about the text change if (noChange) { return; } remAllHigh(); //find the row and column of the active cell int r = 0; int c = 0; cellToRC(this.ActiveControl.TabIndex - 1, ref r, ref c); //if the cell was just entered and the text changed to "" if (recentEnter) { recentEnter = false; lastCell = r * 9 + c; return; } //find what number they entered int number = 0; if (this.ActiveControl.Text.Length != 0 && //they entered something AND this.ActiveControl.Text.ToCharArray()[0] <= 57 && //the entered text is valid AND this.ActiveControl.Text.ToCharArray()[0] >= 49 && //the entered text is valid AND ( ( solv[r * 9 + c,this.ActiveControl.Text.ToCharArray()[0] - 49] != 0 ) || //1. the possibility exists OR ( solv[r * 9 + c,this.ActiveControl.Text.ToCharArray()[0] - 49] == 0 && //2a the possibility does not exist AND grid[r, c] != 0) ) ) //2b it doesnt exist BECAUSE there was another number in there before { //number is 1-based number = ((int) this.ActiveControl.Text.ToCharArray()[0]) - 48; if (grid[r, c] != 0) //if there was a number there before they entered this one { //find out if any cell in it's row, col, or box has that same number for (int rcb = 1; rcb <= 3; rcb++) { for (int n = 0; n < 9; n++) { int cell = nToRowColBox( n, r, c, rcb ); cellToRC( cell, ref row, ref col ); if (grid[row,col] == number) { number = 0; break; } } } } } //update the grid and solv matrices if (number == 0) { if (grid[r,c] != 0) { total -= 1; FoundLabel.Text = total.ToString() + " Found"; numGone( grid[r,c] - 1, this.ActiveControl.TabIndex - 1 ); grid[r,c] = 0; for (int n = 0; n < 9; n++) { solv[r * 9 + c,n] = 1; } //eliminate all obviously wrong poss. and display all cells elimObvPoss(); } } else { if (grid[r,c] == 0) { total += 1; FoundLabel.Text = total.ToString() + " Found"; grid[r,c] = number; } else { numGone( grid[r,c] - 1, this.ActiveControl.TabIndex - 1 ); grid[r,c] = number; //eliminate all obviously wrong poss. and display all cells elimObvPoss(); } for (int n = 0; n < 9; n++) { solv[r*9+c,n] = 0; } //since they put a number in, eliminate all of those choices int[] keepIn = {this.ActiveControl.TabIndex - 1}; updateSolv( number - 1, keepIn, 4, false); this.thecells[ r * 9 + c ].BackColor = highColor; } display(r*9+c); puzzleStr = puzzleStr.Substring(0, r * 9 + c + 1) + number.ToString() + puzzleStr.Substring(r * 9 + c + 2); textBox1.Text = puzzleStr; } void CellEnter(object sender, System.EventArgs e) { remAllHigh(); recentEnter = true; this.ActiveControl.Font = new System.Drawing.Font("Parade", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); recentEnter = true; this.ActiveControl.Text = ""; } void SolveButtonClick(object sender, System.EventArgs e) { //make it do all the tests findOne = false; doStep = false; testLimit = 7; solve(); } void CellLeave(object sender, System.EventArgs e) { remAllHigh(); if ( thecells[lastCell].Text.Length != 2 ) { display(lastCell); } } void TextBox1KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { if (e.KeyChar == (char)13) { remAllHigh(); textToGrid(); startEqualsSolv(); } } void ClearButtonClick(object sender, System.EventArgs e)//CB { textBox1.Text = puzzleStr = " 000000000000000000000000000000000000000000000000000000000000000000000000000000000"; clear(); } void NewButtonClick(object sender, System.EventArgs e) { clear(); //pick the next puzzle puzzleIndex++; if (puzzleIndex == puzzleList.Count) { puzzleIndex = 0; } textBox1.Text = (string)puzzleList[puzzleIndex]; textToGrid(); startEqualsSolv(); //reset findOne = false; doStep = false; testLimit = 0; remAllHigh(); } void TestButtonClick(object sender, System.EventArgs e) { tempInt = total; testLimit = testLimit + 1; if (testLimit >= 7) { testLimit = 1; } solve(); string[] methods = {"Singles", "Naked Groups", "Hidden Groups", "Shared Singles", "Grids", "XY-Wings"}; StatusLabel.Text = methods[testLimit - 1] + ":\n" + (total - tempInt).ToString() + " Found,\n" + elimCount.ToString() + " Elim."; elimCount = 0; highlight(); highCells.Clear(); if (total == 81) { donePuzzle(StatusLabel.Text); } } void FindButtonClick(object sender, System.EventArgs e) { testLimit = 7; findOne = true; solve(); if (total == 81) { donePuzzle(""); } } void StepButtonClick(object sender, System.EventArgs e) { remAllHigh(); //only do one instance of one test - whether it eliminates a possibility(s) or finds a cell testLimit = 7; doStep = true; solve(); elimCount = 0; highlight(); highCells.Clear(); if (total == 81) { donePuzzle(""); } } void ResetButtonClick(object sender, System.EventArgs e) { textBox1.Text = startPuzzle; textToGrid(); //reset for (int n=0; n<=80; n++) { for (int i=0; i<=8; i++) { solv[n,i] = startSolv[n,i]; } } displayAll(); findOne = false; doStep = false; testLimit = 0; remAllHigh(); } void QuitSudoku(object sender, System.EventArgs e) { Application.Exit(); } void Copy (object sender, System.EventArgs e) { Clipboard.SetDataObject(textBox1.Text, true); } void CopyBoth(object sender, System.EventArgs e)//CB { tempString = "Puzzle: " + textBox1.Text + @" ------------------------------------------------------- "; for (int colCB = 0; colCB < 9; colCB++) { for (int spossCB = 0; spossCB < 9; spossCB += 3) { for (int cellCB = 9 * colCB; cellCB < 9 + 9 * colCB; cellCB++) { if ((int)(cellCB / 3) - (double)(cellCB / 3.0) == 0.0) { tempString = tempString + "| "; } for (int possCB = spossCB; possCB < spossCB + 3; possCB++) { if (solv[cellCB, possCB] == 1) { tempString += (possCB + 1).ToString(); } else { tempString += "-"; } } tempString = tempString + " "; } tempString = tempString + @"| "; } if (colCB == 2 || colCB == 5 || colCB == 8) { tempString = tempString + @"------------------------------------------------------- "; } else { tempString = tempString + @"| | | | "; } } tempString = tempString + total.ToString() + " Found"; Clipboard.SetDataObject(tempString, true); } void Paste (object sender, System.EventArgs e) { //textBox1.Text = Clipboard.GetDataObject().GetData( ).ToString(); } void RemAllHigh(object sender, System.EventArgs e)//RH { remAllHigh(); } void RemHigh(object sender, System.EventArgs e) { if (this.ActiveControl.TabIndex < 1 || this.ActiveControl.TabIndex > 81) { return; } char[] tempArray = this.ActiveControl.Name.Substring(4).ToCharArray(); this.thecells[ ((int) tempArray[0] - 48) * 10 + ((int) tempArray[1] - 48) - 1].BackColor = normColor; } void AddHigh(object sender, System.EventArgs e) { if (this.ActiveControl.TabIndex < 1 || this.ActiveControl.TabIndex > 81) { return; } this.thecells[ this.ActiveControl.TabIndex - 1 ].BackColor = highColor; } void SavePosition(object sender, System.EventArgs e) { startPuzzle = puzzleStr; startEqualsSolv(); } void InvertHigh(object sender, System.EventArgs e) { for (int iRH = 0; iRH < 81; iRH++) { if (this.thecells[iRH].BackColor == normColor) { this.thecells[iRH].BackColor = highColor; } else { this.thecells[iRH].BackColor = normColor; } } } void EmptyCell(object sender, System.EventArgs e)//EC { int cellEC = this.ActiveControl.TabIndex - 1; cellToRC( cellEC, ref row, ref col ); if (grid[row,col] != 0) { total -= 1; FoundLabel.Text = total.ToString() + " Found"; numGone( grid[row,col] - 1, cellEC ); grid[row,col] = 0; for (int nEC = 0; nEC < 9; nEC++) { solv[row * 9 + col,nEC] = 1; } //eliminate all obviously wrong poss. and display all cells elimObvPoss(); } for (int nEC = 0; nEC < 9; nEC++) { solv[row * 9 + col,nEC] = 1; } this.thecells[ row * 9 + col ].BackColor = highColor; } void FillCell(object sender, System.EventArgs e)//FC { if (this.ActiveControl.TabIndex < 1 || this.ActiveControl.TabIndex > 81) { return; } //find which number they want to make it (0-based) int numFC = (int) sender.ToString().Substring(sender.ToString().Length - 1).ToCharArray()[0] - 49; //find out which cell (0-based) int cellFC = this.ActiveControl.TabIndex - 1; int r = 0; int c = 0; cellToRC( cellFC, ref r, ref c ); if ( ( solv[r * 9 + c, numFC] != 0 ) || //1. the possibility exists OR ( solv[r * 9 + c, numFC] == 0 && //2a the possibility does not exist AND grid[r, c] != 0) ) //2b it doesnt exist BECAUSE there was another number in there before { //number is 0-based if (grid[r, c] != 0) //if there was a number there before they entered this one { //find out if any cell in it's row, col, or box has that same number for (int rcbFC = 1; rcbFC <= 3; rcbFC++) { for (int nFC = 0; nFC < 9; nFC++) { int incellFC = nToRowColBox( nFC, r, c, rcbFC ); cellToRC( incellFC, ref row, ref col ); if (grid[row,col] == numFC + 1) { return; } } } } //update the grid and solv matrices if (grid[r,c] == 0) { total += 1; FoundLabel.Text = total.ToString() + " Found"; grid[r,c] = numFC + 1; for (int nFC = 0; nFC < 9; nFC++) { solv[r * 9 + c,nFC] = 0; } } else { numGone( grid[r,c] - 1, cellFC ); grid[r,c] = numFC + 1; for (int nFC = 0; nFC < 9; nFC++) { solv[r * 9 + c,nFC] = 0; } //eliminate all obviously wrong poss. and display all cells elimObvPoss(); } for (int nFC = 0; nFC < 9; nFC++) { solv[r*9+c,nFC] = 0; } display(r*9+c); puzzleStr = puzzleStr.Substring(0, r * 9 + c + 1) + (numFC + 1).ToString() + puzzleStr.Substring(r * 9 + c + 2); textBox1.Text = puzzleStr; int[] keepIn = {cellFC}; updateSolv( numFC, keepIn, 4, false ); } this.thecells[ cellFC ].BackColor = highColor; } void ElimPoss(object sender, System.EventArgs e)//EP { //find which number they want to eliminate (0-based) int numEP = (int) sender.ToString().Substring(sender.ToString().Length - 1).ToCharArray()[0] - 49; //find out which cell is the current one (0-based) int cellEP = this.ActiveControl.TabIndex - 1; //make sure the cell is a cell and it does not have a number in it... cellToRC( cellEP, ref row, ref col ); if (cellEP < 0 || cellEP > 81 || grid[row,col] != 0) { return; } //take the poss out of cell's row in solv solv[cellEP, numEP] = 0; //redraw the cell display( cellEP ); this.thecells[ cellEP ].BackColor = highColor; } void TogglePossiblities(object sender, System.EventArgs e) { //toggle the text in the item, and //toggle the color of the poss text if (possColor == normColor) { this.menuItem49.Text = "Don't Show Possibilities"; possColor = textColor; } else { this.menuItem49.Text = "Show Possibilities"; possColor = normColor; } displayAll(); } void ToggleMethodClick(object sender, System.EventArgs e) { Console.WriteLine( sender.ToString() ); } #endregion //the solving methods public void solve( ) { remAllHigh(); int startTotal; do { startTotal = total; if (testLimit == 1 || testLimit == 7) { if (! singles()) { return; } if (total == 81) { donePuzzle(""); break;} } if (testLimit == 2 || testLimit == 7) { if (! nakedGroups()) { return; } if (! singles()) { return; } if (total == 81) { donePuzzle(""); break; } } if (testLimit == 3 || testLimit == 7) { if (! hiddenGroups()) { return; } if (! singles()) { return; } if (total == 81) { donePuzzle(""); break; } } if (testLimit == 4 || testLimit == 7) { if (! sharedSingles()) { return; } if (! singles()) { return; } if (total == 81) { donePuzzle(""); break; } } if (testLimit == 5 || testLimit == 7) { if (! grids()) { return; } if (! singles()) { return; } if (total == 81) { donePuzzle(""); break; } } if (testLimit == 6 || testLimit == 7) { if (! xywings()) { return; } if (! singles()) { return; } if (total == 81) { donePuzzle(""); break; } } //check to see if it should not repeat the whole process again... if (testLimit != 7) { break; } } while (startTotal != total); } public bool singles( ) { LookingInLabel.Text = "Found Cell:"; int tempTotal; //display everything for (int n = 0; n < 81; n++) { display(n); } do { tempTotal = total; //NAKED SINGLES for (int n = 0; n < 81; n++) { int sum = 0; int num = 0; for (int i = 0; i < 9; i++) { sum += solv[n,i]; num += solv[n,i] * i; } if (sum == 1) { //we have found a naked single addTotal( num, n ); StatusLabel.Text = "Found Naked Cell " + (n + 1).ToString(); if (doStep || findOne) { return false; } } } } while (tempTotal != total); do { tempTotal = total; //HIDDEN SINGLES for (int n = 0; n < 9; n++) //look in the 9 rows, cols, and boxs { int[,] sums = new int[6,9]; //make a matrix to represent the 9 cells for (int i = 0; i < 9; i++) //for each row, col, or box, look in all 9 cells { for (int rcb = 0; rcb < 6; rcb += 2) //find hS's in rows, cols, and boxs (0,2,4) { int cell = 0; switch (rcb) { case 0: cell = 9 * n + i; break; case 2: cell = n + 9 * i; break; default: cell = (int) ((double) n/3 - n/3) * 9 + (int) ((double) i/3 - i/3) * 3 + 9 * (3 * (n/3) + i/3); break; } for (int number = 0; number < 9; number++) { if (solv[cell,number] == 1) { sums[rcb, number]++; sums[rcb + 1, number] = cell; } } } } //if we have found a hS for (int rcb = 0; rcb < 6; rcb += 2) { for (int i = 0; i < 9; i++) { if (sums[rcb, i] == 1) { //we have found a hS StatusLabel.Text = "Found Hidden Cell " + (sums[rcb + 1, i]).ToString(); //if it is a hs in two or three of th rcb, addtotal will get called more than once! //could put something here-just let it call, but dont increment total addTotal( i, sums[rcb + 1, i] ); if (doStep || findOne) { return false; } } } } } } while (tempTotal != total); //display everything for (int n = 0; n < 81; n++) { display(n); } return true; } public bool hiddenGroups( ) { LookingInLabel.Text = ""; StatusLabel.Text = ""; //hidden groups are sets of x numbers in x cells. these x number are unique to their x cells //in their r, c, b. There can be other poss in those x cells--these poss are excluded //look in rows, col, and boxs for (int rcb = 1; rcb <= 3; rcb++) { for (int n = 1; n <= 9; n++) { int row, col; switch (rcb) { case 1: row = n - 1; col = 0; break; case 2: col = n - 1; row = 0; break; default: row = (int) Math.Floor((n - 1) / 3) * 3; col = (int) Math.Round(3 * ((double) (n - 1) / 3 - (int) ((n - 1) / 3))); break; } //find all the cells which have something in them ArrayList cells = new ArrayList(); //potential problem (should sum be here or inside the for loop? int sum = 0; for (int i = 0; i < 9; i++) { //the add function on the calculator switch (rcb) { case 1: col = i; break; case 2: row = i; break; default: row = 3 * (int) Math.Floor( row / 3 ) + (int) Math.Floor( i / 3 ); col = 3 * (int) Math.Floor( (col - 1) / 3 ) + (int) Math.Round(3 * ((double) i / 3 - (int) (i / 3))); break; } //use the sum defined earlier for (int j = 0; j < 9; j++) { sum += solv[9 * row + col, j]; } if (sum != 0) { cells.Add( 9 * row + col ); } } //make a matrix representing the possibilities of all of the cells in "cells" //make a matrix that = the sum of the columns in numposs int[,] numposs = new int[cells.Count,9]; ArrayList poss = new ArrayList(9); int[] temp = {0,0,0,0,0,0,0,0,0}; poss.AddRange( temp ); for (int i = 0; i < numposs.GetLength(0); i++) { for (int j = 0; j < 9; j++) { poss[j] = (int)poss[j] + solv[(int)cells[i],j]; numposs[i,j] = solv[(int)cells[i],j]; } } //make poss binary and find the number of non-zero numbers in it sum = 0; for (int i = 0; i < 9; i++) { //if it is 0, it becomes 0, any other number will become 1 poss[i] = (int)poss[i] / Math.Max( (int)poss[i], 1 ); //the number of possibilities in the r, c, b sum += (int)poss[i]; } //make the numbers in poss reflect which possibility they represent for (int i = 0; i < 9; i++) { poss[i] = (int)poss[i] * (i + 1); } poss.Sort(); poss.RemoveRange(0, 9 - sum); //arrange the numbers in poss into all combinations... int ctotal = 0; int depth = 1; ArrayList picks = new ArrayList(); int numspaces = poss.Count; int start = 0; //nsolv isnt used, define it anyway int[,] nsolv = new int[0,0]; for (int numpicks = 2; numpicks < numspaces - 1; numpicks++) { if (! findcomb(start, ctotal, nsolv, numposs, poss, cells, picks, numspaces, numpicks, depth, rcb, 2)) { return false;} } } } return true; } public bool nakedGroups( ) { LookingInLabel.Text = ""; StatusLabel.Text = ""; //naked groups are sets x cells in the same r, c, or b which share exactly x possibilities //the possibilities are taken out of the other cells in the r, c, or b //the next few dozen lines are the same as the ones in hiddenGroups //use rows, columns, and boxes for (int rcb = 1; rcb <= 3; rcb++) { //look in all 9 r, c, b for (int n = 1; n <=9; n++) { int row = 0, col = 0; switch (rcb) { case 1: row = n - 1; break; case 2: col = n - 1; break; default: row = (int) Math.Floor((n - 1) / 3) * 3; col = (int) Math.Round(3 * ((double) (n - 1) / 3 - (int) ((n - 1) / 3))); break; } //find all the cells which have something in them //cells will store the cell numbers that we are talking about ArrayList cells = new ArrayList(); for (int i = 0; i < 9; i++) { //sum is moved to in here as opposed to in hiddenGroups int sum = 0; switch (rcb) //add() { case 1: col = i; break; case 2: row = i; break; default: row = 3 * (int) Math.Floor( row / 3 ) + (int) Math.Floor( i / 3 ); col = 3 * (int) Math.Floor( (col - 1) / 3 ) + (int) Math.Round(3 * ((double) i / 3 - (int) (i / 3))); break; } //use the sum defined earlier for (int j = 0; j < 9; j++) { sum += solv[9 * row + col, j]; } if (sum != 0) { cells.Add( 9 * row + col ); } } //arrange the cell numbers in cells into all combinations int ctotal = 0; int depth = 1; ArrayList picks = new ArrayList(); int numspaces = cells.Count; int start = 0; //this method does not use poss, numposs, nsolv //so define them as empty variables int[,] numposs = new int[0,0]; int[,] nsolv = new int[0,0]; ArrayList poss = new ArrayList(); for (int numpicks = 2; numpicks < numspaces - 1; numpicks++) { if (! findcomb(start, ctotal, nsolv, numposs, poss, cells, picks, numspaces, numpicks, depth, rcb, 1)) { return false; } } } } return true; } public bool sharedSingles( ) { LookingInLabel.Text = ""; StatusLabel.Text = ""; //in speech -- mention why only look for singles, not groups that are shared //shared Singles are groups of two to three cells in the same rb, cb, br, bc that share //a possibility. The possibility in these cells is unique to the cells' r, c, or b //the possibility is then taken out of the r, c, b that they share but where they are not unique //need to look in rows (for cells in the same box) // cols (for cells in the same box) // boxs (for cells in the same row) // boxs (for cells in the same col) for (int rcbb = 3; rcbb <=4; rcbb++) { //in each, look at all 9 rs, cs, bs for (int n = 0; n < 9; n++) { //for each, look at all 9 poss for (int i = 0; i < 9; i++) { int[] cells = new int[9]; int cell; //look at all 9 cells in the r, c, b for (int j = 0; j < 9; j++) { //compile a list of the poss. (0 or 1) in each of the 9 cells //make that list have 3 groups of 3 relating to the r, c, b, b that each group shares //ex-row-{0, 0, 0, 1, 1, 1, 2, 2, 2}-not the right nums, but each num shares a diff box //all cells are zero-based switch (rcbb) { case 1: //row -- for a box cell = 9 * n + j; break; case 2: //col -- for a box cell = 9 * j + n; break; case 3: //box -- for a row cell = 9 * ((int) Math.Floor(n / 3) * 3) + 3 * ((int) Math.Round(3 * ((double) n / 3 - (int) n / 3))) + 9 * ((int) Math.Floor( j / 3 )) + ((int) Math.Round(3 * ((double) j / 3 - (int) (j / 3)))); break; default: //box -- for a col cell = 9 * ((int) Math.Floor(n / 3) * 3) + 3 * ((int) Math.Round(3 * ((double) n / 3 - (int) n / 3))) + 9 * ((int) Math.Round(3 * ((double) j / 3 - (int) (j / 3)))) + ((int) Math.Floor( j / 3 )); break; } //cells will be binary - does the poss exist or not? cells[j] = solv[cell,i]; } //stuff //cells is filled //now sum the three sets of three cells in the list int[] sumcells = new int[3]; sumcells[0] = Math.Sign(cells[0] + cells[1] + cells[2]); sumcells[1] = Math.Sign(cells[3] + cells[4] + cells[5]); sumcells[2] = Math.Sign(cells[6] + cells[7] + cells[8]); //technically, if only one occurance of a number is in the rcb, it will still find it, however, this wont happen very often b/c of hiddenSingles //see if one of the sums is nonzero and the others are zero int maxcells = 0; if (sumcells[0] + sumcells[1] + sumcells[2] == 1) { //sumcells *= {1,2,3} for (int j = 0; j < 3; j++) { sumcells[j] *= j + 1; } //find which group of three it is from maxcells = Math.Max(sumcells[0], Math.Max(sumcells[1] , sumcells[2])); //maxcells is one-based //depnding on rcbb and maxcells, remove the correct possibilities int[] keepIn = new int[3]; switch (rcbb)//why is rcbb allways 3 or 4 here? { case 1: //row -- for a box for (int j = 0; j < 3; j++) { keepIn[j] = j + 9 * n + 3 * (maxcells - 1); } updateSolv( i, keepIn, 3, true ); break; case 2: //col -- for a box for (int j = 0; j < 3; j++) { keepIn[j] = (j * 9) + n + 9 * 3 * (maxcells - 1); } updateSolv( i, keepIn, 3, true ); break; case 3: //box -- for a row for (int j = 0; j < 3; j++) { keepIn[j] = j + ((int) Math.Round(3 * ((double) n / 3 - (int) (n / 3)))) * 3 + 27 * ((int) Math.Floor( n / 3 )) + 9 * (maxcells - 1); } updateSolv( i, keepIn, 1, true ); break; default: //box -- for a col for (int j = 0; j < 3; j++) { keepIn[j] = (j * 9) + ((int) Math.Round(3 * ((double) n / 3 - (int) (n / 3)))) * 3 + 27 * ((int) Math.Floor( n / 3 )) + (maxcells - 1); } updateSolv( i, keepIn, 2, true ); break; } //this ends one sharedsingle //check updatesolv for #elim. //we are done if oneStep was pressed if (doStep && elimCount > 0) { StatusLabel.Text = elimCount.ToString() + " Poss. Elim. (Grids)"; elimCount = 0; return false; } } } } } return true; } public bool grids( ) { LookingInLabel.Text = ""; StatusLabel.Text = ""; //grids comprise a grid of cells, in which the number of rows in the grid = the number of cols //which the certain poss in those rows are in //then, the poss is taken out of all the other cells in each column--not where the cells in grid are, though //look at all possibilities for (int n = 0; n < 9; n++) { //now take the poss from solv-put them into a 9x9 grid called nsolv int[,] nsolv = new int[9,9]; //at the same time, find out which rows/cols have the poss in them int rowtotal; int[] coltotal = new int[9]; ArrayList rcells = new ArrayList(); ArrayList ccells = new ArrayList(); for (int i = 0; i < 9; i++) { rowtotal = 0; for (int j = 0; j < 9; j++) { if (solv[9 * i + j, n] == 1) { rowtotal = 1; coltotal[j] = 1; //take the 9 * i + j th cell-poss from solv, put it in nsolv nsolv[i,j] = 1; } } if (rowtotal == 1) { rcells.Add( i ); } } for (int i = 0; i < 9; i++) { if (coltotal[i] == 1) { ccells.Add( i ); } } //we need to eliminate cells from both rows, and cols, so... //use both rows, and cols for (int rcb = 1; rcb <= 2; rcb++) { ArrayList cells = new ArrayList(); if (rcb == 1) { cells.AddRange( rcells ); } else { cells.AddRange( ccells ); } //cells[cells.Count - 1] is the poss # zero-based cells.Add(n); //call findcomb int ctotal = 0; int depth = 1; ArrayList picks = new ArrayList(); int start = 0; int numspaces = cells.Count - 1; //dont use numposs, poss, but define anyway int[,] numposs = new int[0,0]; ArrayList poss = new ArrayList(); for (int numpicks = 2; numpicks < numspaces; numpicks++) { //in the calc, it redefines cells and nsolv every time here -- why? if (! findcomb( start, ctotal, nsolv, numposs, poss, cells, picks, numspaces, numpicks, depth, rcb, 3 )) { return false; } } } } return true; } public bool xywings( ) { LookingInLabel.Text = ""; StatusLabel.Text = ""; //XYWing finds three cells with two possibilities in them. (x, y, z) //Two are in the same col/row and two are in the same box or row/col. //XYWing first iterates through all 9 rows and cols. For each row/col, it finds //a list of cells with two possibilities. For each comb of two cells in this //list, if they share a number, then it checks both of the cols/rows and boxs, //and looks for a cell which shares both of the numbers that the first two cells //dont share. If a cell is in the same box as the first and the same row/col as //the second, or the same box as the second and the same row/col as the first, //and has the number shared by these two cells, then that number is taken OUT. for (int rcb = 1; rcb <= 2; rcb++) { //look in all 9 r, c for (int n = 0; n < 9; n++) { ArrayList cells = new ArrayList(); ArrayList poss = new ArrayList(); //look in all 9 cells in the r, c for (int i = 0; i < 9; i++) { int row, col; if (rcb == 1) { row = n; col = i; } else { col = n; row = i; } //see how many poss are in the cell in solv //add them up int sum = 0; for (int j = 0; j < 9; j++) { sum += solv[9 * row + col, j]; } if (sum == 2) { //add it to cells cells.Add(9 * row + col); //poss can be used for anything; here it is the opp rcb that these are in if (rcb == 1) { poss.Add(col); } else { poss.Add(row); } } }//end the nine cells in r, c -- call findcomb for every one of these //make sure that now cells has at least 2 entries... if (cells.Count < 2) { continue; } //now cells has all of the binary cells in the r, c //arrange the cell numbers in cells into all combinations of 2 int ctotal = 0; int depth = 1; ArrayList picks = new ArrayList(); int numspaces = cells.Count; int start = 0; //this method does not use numposs, nsolv //so define them as empty variables int[,] numposs = new int[0,0]; int[,] nsolv = new int[0,0]; //this method just does combos of 2, so no loop here... int numpicks = 2; if (! findcomb(start, ctotal, nsolv, numposs, poss, cells, picks, numspaces, numpicks, depth, rcb, 4)) { return false; }; }//end all 9 rs, cs }//end both rs, cs return true; } #region Sub-methods for the solving methods public bool findcomb( int start, int ctotal, int[,] nsolv, int[,] numposs, ArrayList poss, ArrayList cells, ArrayList picks, int numspaces, int numpicks, int depth, int rcb, int testnum ) { //sub-method if (depth - 1 >= picks.Count) { //we are adding this number to picks[depth] which may or may not exist picks.Add( start - 1 ); } else { picks[depth - 1] = start - 1; } while ((int)picks[depth - 1] != numspaces - (numpicks - depth) - 1) { picks[depth - 1] = (int)picks[depth - 1] + 1; if (depth != numpicks) { depth++; start++; if (! findcomb( start, ctotal, nsolv, numposs, poss, cells, picks, numspaces, numpicks, depth, rcb, testnum )) { return false; } depth--; } else { //a combination has been found switch (testnum) { case 2: if (! testHiddenComb( picks, numposs, poss, cells )) { return false; } break; case 3: if (! testGrid( picks, cells, rcb, nsolv )) { return false; } break; case 4: if (! testxywing( picks, cells, rcb, poss )) { return false; } break; default: if (! testNakedComb( picks, cells, rcb)) { return false; } break; } ctotal += 1; } } return true; } public bool testxywing( ArrayList picks, ArrayList cells, int rcb, ArrayList poss )//TX { //cells contains cells that are 0-based //picks contains 0-based numbers that refer to the elements in cells //rcb is 1 or 2 and tells whether the two cells share a row or a col //poss contains cr(b) columns or rows of the cells in cells ArrayList picksposs = new ArrayList(); picksposs.Add( cells[(int)picks[0]] ); picksposs.Add( cells[(int)picks[1]] ); int xTX, yTX, zTX; //xTX, yTX, and zTX will represent the x, y, and z in the xyz wing // xy yz <--rcb=1 // ** zx //see if the two cells chosen share one of their poss. for (yTX = 0; yTX < 9; yTX++) { if (solv[(int)picksposs[0], yTX] + solv[(int)picksposs[1], yTX] == 2) { //they share one poss. (they cant share both, //because then it would have been a naked pair) for (xTX = 0; xTX < 9; xTX++)//find xTX { if (xTX != yTX && solv[(int)picksposs[0], xTX] == 1) { break; } } for (zTX = 0; zTX < 9; zTX++)//find zTX { if (zTX != yTX && solv[(int)picksposs[1], zTX] == 1) { break; } } //now we know xTX, yTX, and zTX where yTX is the shared one //go through both cells, trying to find the third... for (int onetwoTX = 0; onetwoTX < 2; onetwoTX++) { int row = 0; int col = 0; cellToRC( (int)picksposs[onetwoTX], ref row, ref col ); //look in both of the cells' cr(b) where rcb is 1 or 2, for //the 3rd , which would have only both xTX and zTX in it... for (int cellTX = 0; cellTX < 9; cellTX++) { if (findThirdCell( ref picksposs, Math.Abs(rcb - 2) + 1, xTX, yTX, zTX, row, col, cellTX )) { //we have found 3 cells in an acceptable pattern //cells are in picks, nums are in xTX, yTX, zTX elimxywing( picksposs, xTX, yTX, zTX, onetwoTX ); break; } } //look in both of the cells' boxes for the 3rd cell for (int cellTX = 0; cellTX < 9; cellTX++) { if (findThirdCell( ref picksposs, 3, xTX, yTX, zTX, row, col, cellTX )) { //we have found 3 cells in an acceptable pattern //cells are in picks, nums are in xTX, yTX, zTX if (! elimxywing( picksposs, xTX, yTX, zTX, onetwoTX )) { return false; }; break; } } } break; }//end if they share a number }//end going through all the numbers in the first two cells to see if they share return true; }//end sub-method public bool elimxywing( ArrayList picksposs, int xTX, int yTX, int zTX, int onetwoTX )//still TX { //onetwoTX is 0 or 1 //sub-method for xywing //called only by testxywing, when a group of three perfect cells is found. //First, find all cells shared by the two cells in picksposs //that have xTX in them. Then, see if any of those cells have xTX in them. //Take xTX out of the cells that are in this list and have it in them. //the two cells that it needs to intersect are picksposs[2] and picksposs[Math.Abs(onetwoTX - 1)] //go through them both, adding possible cells to a list ArrayList possCellsTX = new ArrayList(); int row = 0; int col = 0; int lastIndexTX = 0; for (int indexTX = Math.Abs(onetwoTX - 1); indexTX <= 2; indexTX += (2 - Math.Abs(onetwoTX - 1))) { for (int rcbTX = 1; rcbTX <= 3; rcbTX++) { for (int nTX = 0; nTX < 9; nTX++) { cellToRC( (int)picksposs[indexTX], ref row, ref col ); int temp = nToRowColBox( nTX, row, col, rcbTX ); if (! picksposs.Contains( temp )) { possCellsTX.Add( temp ); } }//end use all 9 cells in the rcbs }//end look in their rows, cols, boxs //Here, all the cells possible for one of the three //parts of the wing will be in possCellsTX if (indexTX == 2) { //the second time, remove duplicates from just the second cell's possibilities... possCellsTX.Sort(lastIndexTX, possCellsTX.Count - lastIndexTX, System.Collections.Comparer.Default); for (int nTX = lastIndexTX; nTX < possCellsTX.Count - 1; nTX++) { if (possCellsTX[nTX].Equals(possCellsTX[nTX + 1])) { possCellsTX.RemoveAt(nTX); nTX--; } } //then remove non-duplicates possCellsTX.Sort(); for (int nTX = 0; nTX < possCellsTX.Count - 1; nTX++) { if (! possCellsTX[nTX].Equals(possCellsTX[nTX + 1])) { possCellsTX.RemoveAt(nTX); nTX--; } } //remove the last one regardless (112334) -> (134); (1123344) -> (1344) possCellsTX.RemoveAt(possCellsTX.Count - 1); } else { //the first time, just eliminate duplicates possCellsTX.Sort(); for (int nTX = 0; nTX < possCellsTX.Count - 1; nTX++) { if (possCellsTX[nTX].Equals(possCellsTX[nTX + 1])) { possCellsTX.RemoveAt(nTX); nTX--; } } lastIndexTX = possCellsTX.Count; } //the second time, there might be some which still occur twice, //but they dont really matter - xTX will still be removed }//end both cells to intersect //now possCellsTX is a list of the cells from which xTX can be removed -- remove it... foreach (int nTX in possCellsTX) { //the moment of truth! look for xTX if the third wing came off the second; zTX if it came off of the first // xy yz <-> xy yz // xz *z *x xz int thenumTX; if (onetwoTX == 0) { thenumTX = zTX; } else { thenumTX = xTX; } if (solv[nTX, thenumTX] == 1) { //this removes it! solv[nTX, thenumTX] = 0; display(nTX); //right here, if oneStep was called, then add one to elimCount -- quit after elimCount++; highCells.Add( nTX ); //add this to the list so that the program can highlight it later } } if (doStep && elimCount > 0) { StatusLabel.Text = elimCount.ToString() + " Poss. Elim. (XY-wing)"; elimCount = 0; return false; } //now it has taken out all of the possible xTX's return true; }//end elimxywing public bool findThirdCell( ref ArrayList picksposs, int rcbTX , int xTX, int yTX, int zTX, int row, int col, int cellTX)//still TX { //a subroutine for testxywing //rcbTX - find the third cell in a r, c, or b //xTX, yTX, zTX are the three numbers common to the three cells //row, col - the row and col of the cell that we are looking from int totalTX = 0; //iterate through all 9 poss in that cell for (int nTX = 0; nTX < 9; nTX++) { if (solv[nToRowColBox( cellTX, row, col, rcbTX ), nTX] == 1) { if (nTX != xTX && nTX != zTX) { totalTX = 3; break; //if there is a number in the cell which is not //either x or z, then try the next cell } totalTX++; } } //if two poss. matched... if (totalTX == 2) { //we have our cell //it is nToRowColBox( cellTX, row, col, rcbTX picksposs.Add( nToRowColBox( cellTX, row, col, rcbTX ) ); return true; } return false; } public bool testGrid( ArrayList picks, ArrayList cells, int rcb, int[,] nsolv)//TG { //sub-method for grid //rcb is 1 or 2 //cells does not actually have cell #s in it, just #s of rows or cols //take the cells[picks]th rows or cols from nsolv //see if they share picks.count -- if they do, take all the other poss out of the //col or rows which they share //the possibility that we are concerned with is in cells[cells.Count - 1] and 0-based int pTG = (int)cells[cells.Count - 1]; //in the calc, it checks to see if at least one poss exists in the row or col - it always will - why? int[] sumsTG = new int[9]; int sumsumsTG = 0; for (int nTG = 0; nTG < picks.Count; nTG++) { //take cells[picks] row or col from nsolv, add it to sums //use every cell in the row or col cells is 0-based nsolv is binary for (int iTG = 0; iTG < 9; iTG++) { int j; if (rcb == 1) //a row { j = nsolv[(int)cells[(int)picks[nTG]],iTG]; } else //a col { j = nsolv[iTG, (int)cells[(int)picks[nTG]]]; } if (j == 1 && sumsTG[iTG] == 0) { sumsTG[iTG] = 1; sumsumsTG++; } } } //the moment of truth everything is zero-based if (sumsumsTG == picks.Count) { //we have found a grid //take the poss from the row or col of every col or row where there is a one in sums for (int nTG = 0; nTG < 9; nTG++) { //if rcb = 1--nTG is a col where a poss occurres if (sumsTG[nTG] == 1) { int[] keepIn = new int[picks.Count]; //create keepIn with all of the cells mentioned in picks for (int iTG = 0; iTG < picks.Count; iTG++) { if (rcb == 1) //looked in the rows first, take the poss out of the cols { keepIn[iTG] = nTG + 9 * (int)cells[(int)picks[iTG]]; } else //looked in the cols first, take the poss out of the rows { keepIn[iTG] = nTG * 9 + (int)cells[(int)picks[iTG]]; } } //keepIn is created; call updateSolv updateSolv( pTG, keepIn, Math.Abs( rcb - 2 ) + 1, true ); } } //we are done if oneStep was pressed if (doStep && elimCount > 0) { StatusLabel.Text = elimCount.ToString() + " Poss. Elim. (Grids)"; elimCount = 0; return false; } } return true; } public bool testNakedComb( ArrayList picks, ArrayList cells, int rcb)//NC { //sub-method for nakedGroups int[] sumcellsNC = new int[9]; int[] cellsNC = new int[picks.Count]; int sumlistNC = 0; for (int nNC = 0; nNC < picks.Count; nNC++) { //cells contains cells that are 0-based //picks contains 0-based numbers that refer to the elements in cells //cellsNC contains the cells that we are looking at-each cell is 0-based cellsNC[nNC] = (int)cells[(int)picks[nNC]]; for (int iNC = 0; iNC < 9; iNC++) { //copy solv[cells[nHC]] into sumcellsNC //potential problem (undefined value) if (solv[(int)cellsNC[nNC],iNC] == 1 && sumcellsNC[iNC] == 0) { sumcellsNC[iNC]++; sumlistNC++; } } } //if the number of cells involved = the number of poss in those cells if (cellsNC.Length == sumlistNC) { //look at all poss for (int nNC = 0; nNC < 9; nNC++) { //if that possibility is included in those cells if (sumcellsNC[nNC] != 0) { //one of those special moments... //take this poss out of all the other cells in its row or column updateSolv( nNC, cellsNC, rcb, true ); //we are done if oneStep was pressed } } //this ends one ncomb... if (doStep && elimCount > 0) { StatusLabel.Text = elimCount.ToString() + " Poss. Elim. (Grids)"; elimCount = 0; return false; } } return true; } public bool testHiddenComb( ArrayList picks, int[,] numposs, ArrayList poss, ArrayList cells )//HC { //sub-method for hiddenGroups //given picks(poss), look in cells to see if the poss form a hidden group-- //the number of poss equals the number of cells which contain those poss. //If one is found, take every number but picks(poss) from all the cells which share picks(poss). //cells--a list of the cell numbers //numposs--a binary matrix with the poss for all the cells in it //poss--a list of all the poss. in the cells int[] listHC = new int[numposs.GetLength(0)]; int sumlistHC = 0; //this is different than the calc prgm--in the calc, changing picks here wouldnt affect it in findcomb //since it will in C#, use picksposs for this whole method ArrayList picksposs = new ArrayList(picks.Count); picksposs = (ArrayList)picks.Clone(); for (int nHC = 0; nHC < picks.Count; nHC++) { //picksposs is 0-based picksposs[nHC] = (int)poss[(int)picks[nHC]] - 1; for (int iHC = 0; iHC < numposs.GetLength(0); iHC++) { //copy the (picks(nHC))th column of numposs into listHC if (numposs[iHC,(int)picksposs[nHC]] == 1 && listHC[iHC] == 0) { listHC[iHC]++; sumlistHC++; } } } //listHC should be binary at this point if (sumlistHC == picksposs.Count) { //very infrequent but very nice--take every number but picks(poss) from all the cells that share picks(poss) for (int nHC = 0; nHC < listHC.Length; nHC++) { if (listHC[nHC] == 1) { //take the extra nums out of cells[nHC]... int iHC = 0; for (int jHC = 0; jHC < 9; jHC++) //go through all of the numbers (possibilities) { if (jHC != (int)picksposs[iHC]) { if (solv[(int)cells[nHC],jHC] == 1) //if it is actually going to do something { solv[(int)cells[nHC],jHC] = 0; elimCount++; highCells.Add((int)cells[nHC]); //add this so that it can be highlighted later } } else { //assign the next value to iHC if jHC was one of the special possibilities iHC = Math.Min( iHC + 1, picksposs.Count - 1 ); } } } } //we are done if oneStep was pressed if (doStep && elimCount > 0) { StatusLabel.Text = elimCount.ToString() + " Poss. Elim. (Hidden Comb.)"; elimCount = 0; return false; } } return true; } public void addTotal( int num, int cell ) { //addTotal puts a number into a cell and adds 1 to the total variable //num and cell are zero-based //pass in a -1 for num to delete the contents of cell //hs can call this method even if the cell is already filled (see hs) //so... if (solv[cell,num] == 0) { //hs made a mistake return; } //update the grid matrix and the string int[] keepin = { cell }; cellToRC( cell, ref row, ref col ); grid[row,col] = num + 1; puzzleStr = puzzleStr.Substring(0, cell + 1) + (num + 1).ToString() + puzzleStr.Substring(cell + 2); textBox1.Text = puzzleStr; //increase the total by addNum total++; FoundLabel.Text = total.ToString() + " Found"; //update the solv matrix updateSolv( num, keepin, 4, false ); for (int n = 0; n < 9; n++) { solv[cell,n] = 0; } display( cell ); //we have now found one more cell, so if findOne == true, quit solving this.thecells[ cell ].BackColor = highColor; } public void updateSolv( int number, int[] keepIn, int rcba, bool highlightCell )//US { //can take possibilities out of solv //also used as a sub-method of addTotal //number and keepin are zero-based, rcba is one-based //highlightCell tells updateSolv whether to add the cells it elim. poss from to a highlight list (step) //keepIn[0] is the cell where the number was put in, if that exists //create a buffer for the cells that do not change int[,] tempMatUS = new int[keepIn.Length,9]; for (int nUS = 0; nUS < keepIn.Length; nUS++) { for (int iUS = 0; iUS < 9; iUS++) { tempMatUS[nUS,iUS] = solv[keepIn[nUS],iUS]; } } //find out which row and column you are in by looking at keepIn[0] cellToRC( keepIn[0], ref row, ref col ); //take the number out of solv in the correct places, if a poss is actually taken out, add one to elimCount for (int nUS = 0; nUS < 9; nUS++) { int iUS; if (rcba == 1 || rcba == 4) { iUS = row * 9 + nUS; if (solv[iUS,number] == 1) { solv[iUS,number] = 0; display(iUS); elimCount++; if (highlightCell) {highCells.Add(iUS);} //add this so that it can be highlighted later } } if (rcba == 2 || rcba == 4) { iUS = nUS * 9 + col; if (solv[iUS,number] == 1) { solv[iUS,number] = 0; display(iUS); elimCount++; if (highlightCell) {highCells.Add(iUS);} //add this so that it can be highlighted later } } if (rcba == 3 || rcba == 4) { iUS = 9 * (3 * (int) Math.Floor(row / 3) + (int) Math.Floor(nUS / 3)) + 3 * (int) Math.Floor(col / 3) + (int) Math.Round(3 * ((double) nUS / 3 - (int) (nUS / 3))); if (solv[iUS,number] == 1) { solv[iUS,number] = 0; display(iUS); elimCount++; if (highlightCell) {highCells.Add(iUS);} //add this so that it can be highlighted later } } } //put the cells from the buffer back into solv int solvTotalUS; int tempTotalUS; for (int nUS = 0; nUS < keepIn.Length; nUS++) { solvTotalUS = 0; tempTotalUS = 0; for (int iUS = 0; iUS < 9; iUS++) { //make up for any additions to elimCount that were made in one of these cells solvTotalUS += solv[keepIn[nUS],iUS]; tempTotalUS += tempMatUS[nUS,iUS]; } if (solvTotalUS != tempTotalUS) //if anything changed... { elimCount = elimCount - (tempTotalUS - solvTotalUS);//subtract the correct number for (int iUS = 0; iUS < 9; iUS++) { solv[keepIn[nUS],iUS] = tempMatUS[nUS,iUS]; //change it back display(keepIn[nUS]); //display the changed cell while (highCells.Contains( keepIn[nUS] )) //remove those cells which poss were taken out of but were { //wrongly put into the list to be highlighted highCells.Remove( keepIn[nUS] ); } } } } } public void display( int cellDI )//DI { //sub-method //cellDI is 0-based noChange = true; //could maybe call cellToRC int rowDI = cellDI / 9; int colDI = (int) Math.Round(9 * ((double) cellDI / 9 - (int) (cellDI / 9))); if (grid[rowDI, colDI] != 0) { thecells[cellDI].Font = new System.Drawing.Font("Parade", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); thecells[cellDI].ForeColor = textColor; thecells[cellDI].Text = " " + grid[rowDI, colDI].ToString(); } else { string strDI = " 1 2 3\n 4 5 6\n 7 8 9"; for (int columnDI = 0; columnDI < 9; columnDI++) { if( solv[cellDI,columnDI] == 0 ) { strDI = strDI.Replace((columnDI + 1).ToString(), " "); } } //if the text changed or it's color changed, then redisplay it... if (strDI.CompareTo( thecells[cellDI].Text ) != 0 || thecells[cellDI].ForeColor != possColor) { thecells[cellDI].Font = new System.Drawing.Font("Courier New", 6.65F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); thecells[cellDI].ForeColor = possColor; //redisplay the cell... thecells[cellDI].Text = strDI; } } noChange = false; } public void displayAll( )//DA { //display everything for (int nDA = 0; nDA < 81; nDA++) { display(nDA); } } public void cellToRC( int nRC, ref int row, ref int col )//RC { //sub-method //celltoRC uses a zero-based cellnumber and zero-based col and row row = (int) Math.Floor(nRC / 9); col = (int) Math.Round(9 * ( (double) nRC / 9 - (int) (nRC / 9))); } public int nToRowColBox( int nNR, int rowNR, int colNR, int rcbNR )//NR { //sub-method //nNR is an int 0-8 //rowNR and colNR are zero based cells //rcbNR is 1, 2, or 3 //it returns a zero-based cell number switch (rcbNR) { case 1: return 9 * rowNR + nNR; case 2: return nNR * 9 + colNR; default: return 9 * (3 * (int) Math.Floor(rowNR / 3) + (int) Math.Floor(nNR / 3)) + 3 * (int) Math.Floor(colNR / 3) + (int) Math.Round(3 * ((double) nNR / 3 - (int) (nNR / 3))); } } public void startEqualsSolv( ) { for (int n=0; n<=80; n++) { for (int i=0; i<=8; i++) { startSolv[n,i] = solv[n,i]; } } } public void donePuzzle( string dispDP )//DP { remAllHigh(); SearchingForLabel.Text = "DONE!"; LookingInLabel.Text = ""; StatusLabel.Text = dispDP; } #endregion #region Sub-methods for the events public void textToGrid( ) { clear(); //take the string in textBox1 and put it into the grid //but only if the string is long enough if (textBox1.Text.Length == 81) { textBox1.Text = " " + textBox1.Text; } if ((textBox1.Text.Length != 82) || (textBox1.Text.Length == 82 && textBox1.Text.Substring(0,1) != " ")) { textBox1.Text = puzzleStr; return; } char[] charArrayTB = textBox1.Text.ToCharArray(); total = 0; string puzzleStrTemp = " "; for (int nTB = 1; nTB < 82; nTB++) { //the cell is (nTB - 1), the number is ((int) charArrayTB[nTB] - 48) int numberTB = (int) charArrayTB[nTB] - 48; if (numberTB >= 1 && numberTB <= 9) { addTotal( numberTB - 1, nTB - 1 ); puzzleStrTemp += textBox1.Text.Substring(nTB, 1); //total++; } else { numberTB = 0; puzzleStrTemp += "0"; } //cellToRC( nTB - 1, ref row, ref col ); //grid[row,col] = numberTB; } FoundLabel.Text = total.ToString() + " Found"; updateSolvStart(); textBox1.Text = startPuzzle = puzzleStr = puzzleStrTemp; elimCount = 0; } public void updateSolvStart( )//UT { //used at the beginning to redraw all the cells every time //updateSolvStart just changes all of the cells every time to avoid confusion for (int n = 0; n < 81; n++) { for (int i = 0; i < 9; i++) { this.solv[n,i] = 1; } } //eliminate all obviously wrong poss. elimObvPoss(); displayAll(); } public void elimObvPoss( )//OP { //eliminates all possibilities that are rendered wrong by a number being in a cell in //their r, b, c. Then it redraws these cells for (int jOP = 0; jOP < 81; jOP++) { //find out which row and column you are in by looking at using j cellToRC( jOP, ref col, ref row ); if (grid[row, col] == 0) { continue; } for (int nOP = 0; nOP < 9; nOP++) { solv[row * 9 + col,nOP] = 0; } int numberOP = grid[row, col] - 1; //take number out of solv in the correct places for (int nOP = 0; nOP < 9; nOP++) { int iOP; iOP = row * 9 + nOP; solv[iOP,numberOP] = 0; iOP = nOP * 9 + col; solv[iOP,numberOP] = 0; iOP = 9 * (3 * (int) Math.Floor(row / 3) + (int) Math.Floor(nOP / 3)) + 3 * (int) Math.Floor(col / 3) + (int) Math.Round(3 * ((double) nOP / 3 - (int) (nOP / 3))); solv[iOP,numberOP] = 0; } } //display all cells displayAll(); } public void clear( ) { remAllHigh(); SearchingForLabel.Text = LookingInLabel.Text = StatusLabel.Text = ""; //store all 0s to textBox1 string and puzzleStr string grid = new int[9,9]; FoundLabel.Text = "0 Found"; updateSolvStart(); } public void numGone( int numNG, int cellNG )//NG { //called when a number has been taken out of a cell //cellNG and numNG are zero-based //put the number that used to be in this cell (numNG) back into //all affected cells in its r,c,b (from cellNG) cellToRC( cellNG, ref row, ref col ); //put number back into solv in the correct places for (int rcbNG = 1; rcbNG < 4; rcbNG++) { for (int nNG = 0; nNG < 9; nNG++) { solv[nToRowColBox( nNG, row, col, rcbNG), numNG] = 1; } } //total, and its label, will be updated separately } public void highlight( )//HL { foreach( int iHL in highCells ) { this.thecells[ iHL ].BackColor = highColor; } } public void remAllHigh( ) { for (int iRH = 0; iRH < 81; iRH++) { this.thecells[iRH].BackColor = normColor; } } #endregion #region Define global variables //the cell objects in a 81 element list System.Windows.Forms.RichTextBox[] thecells = new System.Windows.Forms.RichTextBox[81]; //the puzzle grid represented as a 9x9 matrix int[,] grid = new int[9,9]; //the possibilities represented as a 81x9 binary matrix int[,] solv = new int[81,9]; //a string to represent the puzzle (essentially the grid matrix) string puzzleStr = " 000000000000000000000000000000000000000000000000000000000000000000000000000000000"; //the puzzle and solv as it was at the beginning of the solving string startPuzzle = " 000000000000000000000000000000000000000000000000000000000000000000000000000000000"; int[,] startSolv = new int[81,9]; //two boolean values to help with events bool recentEnter = false; bool noChange = false; //variable designating the last cell visited int lastCell = 0; //the total number of cells filled in int total = 0; //two very common variables int row, col; //temp vars string tempString; int tempInt; //a list of puzzles one can solve ArrayList puzzleList = new ArrayList(); //make an index for the list int puzzleIndex = -1; //stuff to control how many tests to do at a time, etc int testLimit = 0; bool findOne = false; bool doStep = false; int elimCount = 0; //for Step ArrayList highCells = new ArrayList(); //for Step //the color to highlight with and the normal color and the poss color and the text (normal) color System.Drawing.Color highColor = System.Drawing.Color.LightYellow; System.Drawing.Color normColor = System.Drawing.Color.PaleGreen; System.Drawing.Color textColor = System.Drawing.Color.Black; System.Drawing.Color possColor = System.Drawing.Color.Black; #endregion private void InitializeComponent() { this.menuItem11 = new System.Windows.Forms.MenuItem(); this.menuItem46 = new System.Windows.Forms.MenuItem(); this.menuItem47 = new System.Windows.Forms.MenuItem(); this.SearchingForLabel = new System.Windows.Forms.Label(); this.menuItem45 = new System.Windows.Forms.MenuItem(); this.menuItem8 = new System.Windows.Forms.MenuItem(); this.mainMenu1 = new System.Windows.Forms.MainMenu(); this.TestButton = new System.Windows.Forms.Button(); this.menuItem4 = new System.Windows.Forms.MenuItem(); this.menuItem5 = new System.Windows.Forms.MenuItem(); this.menuItem6 = new System.Windows.Forms.MenuItem(); this.menuItem7 = new System.Windows.Forms.MenuItem(); this.menuItem0 = new System.Windows.Forms.MenuItem(); this.menuItem1 = new System.Windows.Forms.MenuItem(); this.menuItem2 = new System.Windows.Forms.MenuItem(); this.menuItem3 = new System.Windows.Forms.MenuItem(); this.menuItem16 = new System.Windows.Forms.MenuItem(); this.ClearButton = new System.Windows.Forms.Button(); this.StatusLabel = new System.Windows.Forms.Label(); this.SolveButton = new System.Windows.Forms.Button(); this.FindButton = new System.Windows.Forms.Button(); this.panel1 = new System.Windows.Forms.Panel(); this.NewButton = new System.Windows.Forms.Button(); this.menuItem21 = new System.Windows.Forms.MenuItem(); this.LookingInLabel = new System.Windows.Forms.Label(); this.textBox1 = new System.Windows.Forms.TextBox(); this.menuItem39 = new System.Windows.Forms.MenuItem(); this.menuItem38 = new System.Windows.Forms.MenuItem(); this.menuItem37 = new System.Windows.Forms.MenuItem(); this.menuItem36 = new System.Windows.Forms.MenuItem(); this.menuItem35 = new System.Windows.Forms.MenuItem(); this.menuItem34 = new System.Windows.Forms.MenuItem(); this.menuItem33 = new System.Windows.Forms.MenuItem(); this.menuItem32 = new System.Windows.Forms.MenuItem(); this.menuItem31 = new System.Windows.Forms.MenuItem(); this.menuItem30 = new System.Windows.Forms.MenuItem(); this.FoundLabel = new System.Windows.Forms.Label(); this.menuItem59 = new System.Windows.Forms.MenuItem(); this.menuItem58 = new System.Windows.Forms.MenuItem(); this.menuItem51 = new System.Windows.Forms.MenuItem(); this.menuItem50 = new System.Windows.Forms.MenuItem(); this.menuItem53 = new System.Windows.Forms.MenuItem(); this.menuItem52 = new System.Windows.Forms.MenuItem(); this.menuItem55 = new System.Windows.Forms.MenuItem(); this.menuItem54 = new System.Windows.Forms.MenuItem(); this.menuItem57 = new System.Windows.Forms.MenuItem(); this.menuItem56 = new System.Windows.Forms.MenuItem(); this.menuItem28 = new System.Windows.Forms.MenuItem(); this.menuItem29 = new System.Windows.Forms.MenuItem(); this.menuItem26 = new System.Windows.Forms.MenuItem(); this.menuItem27 = new System.Windows.Forms.MenuItem(); this.menuItem24 = new System.Windows.Forms.MenuItem(); this.menuItem25 = new System.Windows.Forms.MenuItem(); this.menuItem9 = new System.Windows.Forms.MenuItem(); this.menuItem23 = new System.Windows.Forms.MenuItem(); this.menuItem20 = new System.Windows.Forms.MenuItem(); this.menuItem19 = new System.Windows.Forms.MenuItem(); this.resetButton = new System.Windows.Forms.Button(); this.StepButton = new System.Windows.Forms.Button(); this.menuItem15 = new System.Windows.Forms.MenuItem(); this.menuItem14 = new System.Windows.Forms.MenuItem(); this.menuItem17 = new System.Windows.Forms.MenuItem(); this.menuItem48 = new System.Windows.Forms.MenuItem(); this.menuItem49 = new System.Windows.Forms.MenuItem(); this.menuItem10 = new System.Windows.Forms.MenuItem(); this.menuItem13 = new System.Windows.Forms.MenuItem(); this.menuItem12 = new System.Windows.Forms.MenuItem(); this.menuItem22 = new System.Windows.Forms.MenuItem(); this.menuItem18 = new System.Windows.Forms.MenuItem(); this.menuItem40 = new System.Windows.Forms.MenuItem(); this.menuItem41 = new System.Windows.Forms.MenuItem(); this.menuItem42 = new System.Windows.Forms.MenuItem(); this.menuItem43 = new System.Windows.Forms.MenuItem(); this.menuItem44 = new System.Windows.Forms.MenuItem(); this.SuspendLayout(); // // menuItem11 // this.menuItem11.Index = 1; this.menuItem11.Text = "Paste puzzle from clipboard"; this.menuItem11.Click += new System.EventHandler(this.Paste); // // menuItem46 // this.menuItem46.Index = 6; this.menuItem46.Text = "7"; this.menuItem46.Click += new System.EventHandler(this.ElimPoss); // // menuItem47 // this.menuItem47.Index = 7; this.menuItem47.Text = "8"; this.menuItem47.Click += new System.EventHandler(this.ElimPoss); // // SearchingForLabel // this.SearchingForLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.SearchingForLabel.Location = new System.Drawing.Point(384, 80); this.SearchingForLabel.Name = "SearchingForLabel"; this.SearchingForLabel.Size = new System.Drawing.Size(128, 24); this.SearchingForLabel.TabIndex = 206; this.SearchingForLabel.TextAlign = System.Drawing.ContentAlignment.TopCenter; // // menuItem45 // this.menuItem45.Index = 5; this.menuItem45.Text = "6"; this.menuItem45.Click += new System.EventHandler(this.ElimPoss); // // menuItem8 // this.menuItem8.Index = 1; this.menuItem8.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem10, this.menuItem11}); this.menuItem8.Text = "Edit"; // // mainMenu1 // this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem1, this.menuItem8, this.menuItem12, this.menuItem19, this.menuItem3}); // // TestButton // this.TestButton.BackColor = System.Drawing.Color.White; this.TestButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.TestButton.ForeColor = System.Drawing.Color.RoyalBlue; this.TestButton.Location = new System.Drawing.Point(448, 296); this.TestButton.Name = "TestButton"; this.TestButton.Size = new System.Drawing.Size(56, 24); this.TestButton.TabIndex = 86; this.TestButton.Text = "1 Test"; this.TestButton.Click += new System.EventHandler(this.TestButtonClick); // // menuItem4 // this.menuItem4.Index = 0; this.menuItem4.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem5, this.menuItem6, this.menuItem31, this.menuItem32, this.menuItem33, this.menuItem34, this.menuItem35, this.menuItem36, this.menuItem37}); this.menuItem4.Text = "Make this cell a"; // // menuItem5 // this.menuItem5.Index = 0; this.menuItem5.Text = "1"; this.menuItem5.Click += new System.EventHandler(this.FillCell); // // menuItem6 // this.menuItem6.Index = 1; this.menuItem6.Text = "2"; this.menuItem6.Click += new System.EventHandler(this.FillCell); // // menuItem7 // this.menuItem7.Index = 0; this.menuItem7.Text = "Save current position"; this.menuItem7.Click += new System.EventHandler(this.SavePosition); // // menuItem0 // this.menuItem0.Index = 1; this.menuItem0.Text = "Quit sudoku"; this.menuItem0.Click += new System.EventHandler(this.QuitSudoku); // // menuItem1 // this.menuItem1.Index = 0; this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem7, this.menuItem0}); this.menuItem1.Text = "File"; // // menuItem2 // this.menuItem2.Index = 3; this.menuItem2.Text = "Invert all highlights"; this.menuItem2.Click += new System.EventHandler(this.InvertHigh); // // menuItem3 // this.menuItem3.Index = 4; this.menuItem3.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem4, this.menuItem38, this.menuItem39}); this.menuItem3.Text = "This Cell"; // // menuItem16 // this.menuItem16.Index = -1; this.menuItem16.Text = "File"; // // ClearButton // this.ClearButton.BackColor = System.Drawing.Color.White; this.ClearButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.ClearButton.ForeColor = System.Drawing.Color.RoyalBlue; this.ClearButton.Location = new System.Drawing.Point(384, 320); this.ClearButton.Name = "ClearButton"; this.ClearButton.Size = new System.Drawing.Size(56, 24); this.ClearButton.TabIndex = 85; this.ClearButton.Text = "Clear"; this.ClearButton.Click += new System.EventHandler(this.ClearButtonClick); // // StatusLabel // this.StatusLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.StatusLabel.Location = new System.Drawing.Point(384, 152); this.StatusLabel.Name = "StatusLabel"; this.StatusLabel.Size = new System.Drawing.Size(128, 64); this.StatusLabel.TabIndex = 209; this.StatusLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // SolveButton // this.SolveButton.BackColor = System.Drawing.Color.White; this.SolveButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.SolveButton.ForeColor = System.Drawing.Color.RoyalBlue; this.SolveButton.Location = new System.Drawing.Point(400, 240); this.SolveButton.Name = "SolveButton"; this.SolveButton.Size = new System.Drawing.Size(96, 32); this.SolveButton.TabIndex = 83; this.SolveButton.Text = "Solve"; this.SolveButton.Click += new System.EventHandler(this.SolveButtonClick); // // FindButton // this.FindButton.BackColor = System.Drawing.Color.White; this.FindButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.FindButton.ForeColor = System.Drawing.Color.RoyalBlue; this.FindButton.Location = new System.Drawing.Point(448, 320); this.FindButton.Name = "FindButton"; this.FindButton.Size = new System.Drawing.Size(56, 24); this.FindButton.TabIndex = 87; this.FindButton.Text = "Find 1"; this.FindButton.Click += new System.EventHandler(this.FindButtonClick); // // panel1 // this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.panel1.Location = new System.Drawing.Point(0, 0); this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Size(376, 376); this.panel1.TabIndex = 211; // // NewButton // this.NewButton.BackColor = System.Drawing.Color.White; this.NewButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.NewButton.ForeColor = System.Drawing.Color.RoyalBlue; this.NewButton.Location = new System.Drawing.Point(384, 296); this.NewButton.Name = "NewButton"; this.NewButton.Size = new System.Drawing.Size(56, 24); this.NewButton.TabIndex = 84; this.NewButton.Text = "New"; this.NewButton.Click += new System.EventHandler(this.NewButtonClick); // // menuItem21 // this.menuItem21.Index = -1; this.menuItem21.Text = "Highlight Current Cell"; this.menuItem21.Click += new System.EventHandler(this.AddHigh); // // LookingInLabel // this.LookingInLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.LookingInLabel.Location = new System.Drawing.Point(384, 128); this.LookingInLabel.Name = "LookingInLabel"; this.LookingInLabel.Size = new System.Drawing.Size(128, 24); this.LookingInLabel.TabIndex = 208; this.LookingInLabel.TextAlign = System.Drawing.ContentAlignment.TopCenter; // // textBox1 // this.textBox1.BackColor = System.Drawing.SystemColors.Control; this.textBox1.BorderStyle = System.Windows.Forms.BorderStyle.None; this.textBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.textBox1.Location = new System.Drawing.Point(16, 376); this.textBox1.MaxLength = 82; this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(512, 13); this.textBox1.TabIndex = 210; this.textBox1.Text = "000000000000000000000000000000000000000000000000000000000000000000000000000000000" + ""; this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.TextBox1KeyPress); // // menuItem39 // this.menuItem39.Index = 2; this.menuItem39.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem40, this.menuItem41, this.menuItem42, this.menuItem43, this.menuItem44, this.menuItem45, this.menuItem46, this.menuItem47, this.menuItem48}); this.menuItem39.Text = "Eliminate a possibility"; // // menuItem38 // this.menuItem38.Index = 1; this.menuItem38.Text = "Make this cell empty"; this.menuItem38.Click += new System.EventHandler(this.EmptyCell); // // menuItem37 // this.menuItem37.Index = 8; this.menuItem37.Text = "9"; this.menuItem37.Click += new System.EventHandler(this.FillCell); // // menuItem36 // this.menuItem36.Index = 7; this.menuItem36.Text = "8"; this.menuItem36.Click += new System.EventHandler(this.FillCell); // // menuItem35 // this.menuItem35.Index = 6; this.menuItem35.Text = "7"; this.menuItem35.Click += new System.EventHandler(this.FillCell); // // menuItem34 // this.menuItem34.Index = 5; this.menuItem34.Text = "6"; this.menuItem34.Click += new System.EventHandler(this.FillCell); // // menuItem33 // this.menuItem33.Index = 4; this.menuItem33.Text = "5"; this.menuItem33.Click += new System.EventHandler(this.FillCell); // // menuItem32 // this.menuItem32.Index = 3; this.menuItem32.Text = "4"; this.menuItem32.Click += new System.EventHandler(this.FillCell); // // menuItem31 // this.menuItem31.Index = 2; this.menuItem31.Text = "3"; this.menuItem31.Click += new System.EventHandler(this.FillCell); // // menuItem30 // this.menuItem30.Index = 5; this.menuItem30.Text = "Do a small step"; this.menuItem30.Click += new System.EventHandler(this.StepButtonClick); // // FoundLabel // this.FoundLabel.BackColor = System.Drawing.Color.White; this.FoundLabel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.FoundLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.FoundLabel.ForeColor = System.Drawing.Color.RoyalBlue; this.FoundLabel.Location = new System.Drawing.Point(400, 24); this.FoundLabel.Name = "FoundLabel"; this.FoundLabel.Size = new System.Drawing.Size(96, 32); this.FoundLabel.TabIndex = 200; this.FoundLabel.Text = "0 Found"; this.FoundLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // menuItem59 // this.menuItem59.Checked = true; this.menuItem59.Index = 7; this.menuItem59.RadioCheck = true; this.menuItem59.Text = "X-Y Wings"; // // menuItem58 // this.menuItem58.Checked = true; this.menuItem58.Index = 6; this.menuItem58.RadioCheck = true; this.menuItem58.Text = "Grids"; // // menuItem51 // this.menuItem51.Index = 1; this.menuItem51.Text = "Puzzle with possibilities"; this.menuItem51.Click += new System.EventHandler(this.CopyBoth); // // menuItem50 // this.menuItem50.Index = 0; this.menuItem50.Text = "Just the puzzle"; this.menuItem50.Click += new System.EventHandler(this.Copy); // // menuItem53 // this.menuItem53.Checked = true; this.menuItem53.Index = 1; this.menuItem53.RadioCheck = true; this.menuItem53.Text = "Naked Singles"; // // menuItem52 // this.menuItem52.Checked = true; this.menuItem52.Index = 0; this.menuItem52.RadioCheck = true; this.menuItem52.Text = "Singles"; this.menuItem52.Click += new System.EventHandler(this.ToggleMethodClick); // // menuItem55 // this.menuItem55.Checked = true; this.menuItem55.Index = 3; this.menuItem55.RadioCheck = true; this.menuItem55.Text = "Naked Groups"; // // menuItem54 // this.menuItem54.Checked = true; this.menuItem54.Index = 2; this.menuItem54.RadioCheck = true; this.menuItem54.Text = "Hidden Singles"; // // menuItem57 // this.menuItem57.Checked = true; this.menuItem57.Index = 5; this.menuItem57.RadioCheck = true; this.menuItem57.Text = "Shared Possibilities"; // // menuItem56 // this.menuItem56.Checked = true; this.menuItem56.Index = 4; this.menuItem56.RadioCheck = true; this.menuItem56.Text = "Hidden Groups"; // // menuItem28 // this.menuItem28.Index = 3; this.menuItem28.Text = "Do 1 solving method"; this.menuItem28.Click += new System.EventHandler(this.TestButtonClick); // // menuItem29 // this.menuItem29.Index = 4; this.menuItem29.Text = "Find 1 number"; this.menuItem29.Click += new System.EventHandler(this.FindButtonClick); // // menuItem26 // this.menuItem26.Index = 1; this.menuItem26.Text = "Un-highlight current cell"; this.menuItem26.Click += new System.EventHandler(this.RemHigh); // // menuItem27 // this.menuItem27.Index = 2; this.menuItem27.Text = "Remove all highlights"; this.menuItem27.Click += new System.EventHandler(this.RemAllHigh); // // menuItem24 // this.menuItem24.Index = -1; this.menuItem24.Text = "Highlight Current Cell"; this.menuItem24.Click += new System.EventHandler(this.AddHigh); // // menuItem25 // this.menuItem25.Index = 0; this.menuItem25.Text = "Highlight current cell"; this.menuItem25.Click += new System.EventHandler(this.AddHigh); // // menuItem9 // this.menuItem9.Index = 5; this.menuItem9.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem52, this.menuItem53, this.menuItem54, this.menuItem55, this.menuItem56, this.menuItem57, this.menuItem58, this.menuItem59}); this.menuItem9.Text = "Choose solving methods"; // // menuItem23 // this.menuItem23.Index = -1; this.menuItem23.Text = "Highlight Current Cell"; this.menuItem23.Click += new System.EventHandler(this.AddHigh); // // menuItem20 // this.menuItem20.Index = -1; this.menuItem20.Text = "Highlight Current Cell"; this.menuItem20.Click += new System.EventHandler(this.AddHigh); // // menuItem19 // this.menuItem19.Index = 3; this.menuItem19.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem25, this.menuItem26, this.menuItem27, this.menuItem2, this.menuItem49, this.menuItem9}); this.menuItem19.Text = "Solving Aids"; // // resetButton // this.resetButton.BackColor = System.Drawing.Color.White; this.resetButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.resetButton.ForeColor = System.Drawing.Color.RoyalBlue; this.resetButton.Location = new System.Drawing.Point(384, 344); this.resetButton.Name = "resetButton"; this.resetButton.Size = new System.Drawing.Size(56, 24); this.resetButton.TabIndex = 212; this.resetButton.Text = "Reset"; this.resetButton.Click += new System.EventHandler(this.ResetButtonClick); // // StepButton // this.StepButton.BackColor = System.Drawing.Color.White; this.StepButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.StepButton.ForeColor = System.Drawing.Color.RoyalBlue; this.StepButton.Location = new System.Drawing.Point(448, 344); this.StepButton.Name = "StepButton"; this.StepButton.Size = new System.Drawing.Size(56, 24); this.StepButton.TabIndex = 88; this.StepButton.Text = "1 Step"; this.StepButton.Click += new System.EventHandler(this.StepButtonClick); // // menuItem15 // this.menuItem15.Index = 2; this.menuItem15.Text = "Reset to original"; this.menuItem15.Click += new System.EventHandler(this.ResetButtonClick); // // menuItem14 // this.menuItem14.Index = 1; this.menuItem14.Text = "Blank puzzle"; this.menuItem14.Click += new System.EventHandler(this.ClearButtonClick); // // menuItem17 // this.menuItem17.Index = -1; this.menuItem17.Text = "File"; // // menuItem48 // this.menuItem48.Index = 8; this.menuItem48.Text = "9"; this.menuItem48.Click += new System.EventHandler(this.ElimPoss); // // menuItem49 // this.menuItem49.Index = 4; this.menuItem49.Text = "Don\'t show possibilities"; this.menuItem49.Click += new System.EventHandler(this.TogglePossiblities); // // menuItem10 // this.menuItem10.Index = 0; this.menuItem10.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem50, this.menuItem51}); this.menuItem10.Text = "Copy to clipboard"; // // menuItem13 // this.menuItem13.Index = 0; this.menuItem13.Text = "Make new puzzle"; this.menuItem13.Click += new System.EventHandler(this.NewButtonClick); // // menuItem12 // this.menuItem12.Index = 2; this.menuItem12.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem13, this.menuItem14, this.menuItem15, this.menuItem28, this.menuItem29, this.menuItem30}); this.menuItem12.Text = "Actions"; // // menuItem22 // this.menuItem22.Index = -1; this.menuItem22.Text = "Highlight Current Cell"; this.menuItem22.Click += new System.EventHandler(this.AddHigh); // // menuItem18 // this.menuItem18.Index = -1; this.menuItem18.Text = "File"; // // menuItem40 // this.menuItem40.Index = 0; this.menuItem40.Text = "1"; this.menuItem40.Click += new System.EventHandler(this.ElimPoss); // // menuItem41 // this.menuItem41.Index = 1; this.menuItem41.Text = "2"; this.menuItem41.Click += new System.EventHandler(this.ElimPoss); // // menuItem42 // this.menuItem42.Index = 2; this.menuItem42.Text = "3"; this.menuItem42.Click += new System.EventHandler(this.ElimPoss); // // menuItem43 // this.menuItem43.Index = 3; this.menuItem43.Text = "4"; this.menuItem43.Click += new System.EventHandler(this.ElimPoss); // // menuItem44 // this.menuItem44.Index = 4; this.menuItem44.Text = "5"; this.menuItem44.Click += new System.EventHandler(this.ElimPoss); // // PuzzleGrid // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.BackColor = System.Drawing.SystemColors.Control; this.ClientSize = new System.Drawing.Size(514, 392); this.Controls.Add(this.resetButton); this.Controls.Add(this.StepButton); this.Controls.Add(this.FindButton); this.Controls.Add(this.TestButton); this.Controls.Add(this.NewButton); this.Controls.Add(this.ClearButton); this.Controls.Add(this.StatusLabel); this.Controls.Add(this.LookingInLabel); this.Controls.Add(this.SearchingForLabel); this.Controls.Add(this.FoundLabel); this.Controls.Add(this.SolveButton); this.Controls.Add(this.panel1); this.Controls.Add(this.textBox1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.MaximizeBox = false; this.Menu = this.mainMenu1; this.Name = "PuzzleGrid"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Sudoku"; this.ResumeLayout(false); } } }