private static void createCrozzleInitPosition() { Random rn = new Random(); for (int i = CreateCrozzle.TCSLNRSBWLforloop.Count() - 1; i >= 0; i--) { if (HWP.Count == 0) { int PX = rn.Next(1, 10); int PY = rn.Next(1, (10 - CreateCrozzle.TCSLNRSBWLforloop[i].wordlist.Length)); //int PX = 2; //int PY = 1; addPosition(i, PX, PY, "H"); CreateCrozzle.TCSLNRSBWLforloop.RemoveAt(i); continue; } if (VWP.Count == 0) { bool write = false; foreach (HorizontalWordPosition hwp in HWP) { if (write == false) { for (int k = 0; k < CreateCrozzle.TCSLNRSBWLforloop[i].wordlist.Length; k++) { if (CreateCrozzle.TCSLNRSBWLforloop[i].letter[k] == hwp.letter) { int PX = hwp.X - k; int PY = hwp.Y; //if (CheckPositionValidation.checkPositionExist(i, k, "V", PX, PY) && CheckPositionValidation.checkPositionIntersected(hwp.wholeword)) if (CheckPositionValidation.checkPositionExist(i, "V", PX, PY)) { addPosition(i, PX, PY, "V"); CreateCrozzle.TCSLNRSBWLforloop.RemoveAt(i); write = true; break; } } } } else { break; } } continue; } break; } }
private static void secondTimesCanBePlace() { for (int pi = 0; pi < positionStillCanBePlace.Count(); pi++) { //int x = rn.Next(1, 10); //int y = rn.Next(1, (10 - DataLoad.TCSLNRSBWL[i].wordlist.Length)); ////int PX = 2; ////int PY = 1; int x = positionStillCanBePlace[pi].X; int y = positionStillCanBePlace[pi].Y; if (CheckPositionValidation.checkEmptyPlace3X3(x, y)) { positionSecondCanBePlace.Add(new PositionSecondCanBePlace(x, y)); } } }
private static int otherCrozzlePositionSecondInitPosition(int index) { Random rn = new Random(); int a = CheckPositionValidation.checkCrozzleEdge(); switch (a) { case 0: //for (int pi = 0; pi < positionStillCanBePlace.Count(); pi++) //for (int i = DataLoad.TCSLNRSBWL.Count() - 1; i >= 0; i--) //{ bool writteda = false; while (writteda == false) { //for (int x = DataLoad.TCFL.Row; x >= 1; x--) //{ // for (int y = 1; y <= (DataLoad.TCFL.Column - DataLoad.TCSLNRSBWL[i].wordlist.Length); y++) // { //for (int i = DataLoad.TCSLNRSBWL.Count() - 1; i >= 0; i--) for (int pi = 0; pi < positionSecondCanBePlace.Count(); pi++) { //int x = rn.Next(1, 10); //int y = rn.Next(1, (10 - DataLoad.TCSLNRSBWL[i].wordlist.Length)); ////int PX = 2; ////int PY = 1; int x = positionSecondCanBePlace[pi].X; int y = positionSecondCanBePlace[pi].Y; //if (CheckPositionValidation.checkPositionValidation(index, "H", x, y) && CheckPositionValidation.checkPositionExist(index, "H", x, y) && CheckPositionValidation.checkWordNotIntersected(index, "H", x, y) && CheckPositionValidation.checkEachWordSpaceNotTouch(index, "H", x, y)) if (CheckPositionValidation.checkPositionValidation(index, "H", x, y)) { if (CheckPositionValidation.checkPositionExist(index, "H", x, y)) { if (CheckPositionValidation.checkWordNotIntersected(index, "H", x, y)) { if (CheckPositionValidation.checkEachWordSpaceNotTouch(index, "H", x, y)) { addPosition(index, x, y, "H"); CreateCrozzle.TCSLNRSBWLforloop.RemoveAt(index); writteda = true; return(-1); } } } } } return(index); } //} break; //case 1: // //for (int i = DataLoad.TCSLNRSBWL.Count() - 1; i >= 0; i--) // //{ // bool writtedb = false; // if (writtedb == false) // { // //int PX = rn.Next(1, 10); // //int PY = rn.Next(1, (10 - DataLoad.TCSLNRSBWL[i].wordlist.Length)); // int x = 1; // int y = 1; // //if (CheckPositionValidation.checkPositionValidation(index, "H", x, y) && CheckPositionValidation.checkPositionExist(index, "H", x, y) && CheckPositionValidation.checkWordNotIntersected(index, "H", x, y) && CheckPositionValidation.checkEachWordSpaceNotTouch(index, "H", x, y)) // if (CheckPositionValidation.checkPositionValidation(index, "H", x, y)) // if (CheckPositionValidation.checkPositionExist(index, "H", x, y)) // if (CheckPositionValidation.checkWordNotIntersected(index, "H", x, y)) // if (CheckPositionValidation.checkEachWordSpaceNotTouch(index, "H", x, y)) // { // addPosition(index, x, y, "H"); // CreateCrozzle.TCSLNRSBWLforloop.RemoveAt(index); // writtedb = true; // return -1; // } // //if (CheckPositionValidation.checkPositionValidation(index, "V", x, y) && CheckPositionValidation.checkPositionExist(index, "V", x, y) && CheckPositionValidation.checkWordNotIntersected(index, "V", x, y) && CheckPositionValidation.checkEachWordSpaceNotTouch(index, "V", x, y)) // if (CheckPositionValidation.checkPositionValidation(index, "V", x, y)) // if (CheckPositionValidation.checkPositionExist(index, "V", x, y)) // if (CheckPositionValidation.checkWordNotIntersected(index, "V", x, y)) // if (CheckPositionValidation.checkEachWordSpaceNotTouch(index, "V", x, y)) // { // addPosition(index, x, y, "V"); // CreateCrozzle.TCSLNRSBWLforloop.RemoveAt(index); // writtedb = true; // return -1; // } // } // //} // break; //case 2: // //for (int i = DataLoad.TCSLNRSBWL.Count() - 1; i >= 0; i--) // //{ // bool writtedc = false; // if (writtedc == false) // { // //int PX = rn.Next(1, 10); // //int PY = rn.Next(1, (10 - DataLoad.TCSLNRSBWL[i].wordlist.Length)); // int x = DataLoad.TCFL.Row; // int y = DataLoad.TCFL.Column - CreateCrozzle.TCSLNRSBWLforloop[index].wordlist.Length + 1; // //if (CheckPositionValidation.checkPositionValidation(index, "H", x, y) && CheckPositionValidation.checkPositionExist(index, "H", x, y) && CheckPositionValidation.checkWordNotIntersected(index, "H", x, y) && CheckPositionValidation.checkEachWordSpaceNotTouch(index, "H", x, y)) // if (CheckPositionValidation.checkPositionValidation(index, "H", x, y)) // if (CheckPositionValidation.checkPositionExist(index, "H", x, y)) // if (CheckPositionValidation.checkWordNotIntersected(index, "H", x, y)) // if (CheckPositionValidation.checkEachWordSpaceNotTouch(index, "H", x, y)) // { // addPosition(index, x, y, "H"); // CreateCrozzle.TCSLNRSBWLforloop.RemoveAt(index); // writtedc = true; // return -1; // } // //if (CheckPositionValidation.checkPositionValidation(index, "V", x, y) && CheckPositionValidation.checkPositionExist(index, "V", x, y) && CheckPositionValidation.checkWordNotIntersected(index, "V", x, y) && CheckPositionValidation.checkEachWordSpaceNotTouch(index, "V", x, y)) // if (CheckPositionValidation.checkPositionValidation(index, "V", x, y)) // if (CheckPositionValidation.checkPositionExist(index, "V", x, y)) // if (CheckPositionValidation.checkWordNotIntersected(index, "V", x, y)) // if (CheckPositionValidation.checkEachWordSpaceNotTouch(index, "V", x, y)) // { // addPosition(index, x, y, "V"); // CreateCrozzle.TCSLNRSBWLforloop.RemoveAt(index); // writtedc = true; // return -1; // } // } // //} // break; } return(index); }
private static int otherCrozzlePosition(int index) { for (int k = CreateCrozzle.TCSLNRSBWLforloop[index].wordlist.Length - 1; k >= 0; k--) { foreach (VerticalWordPosition vwp in VWP) { if (CreateCrozzle.TCSLNRSBWLforloop[index].letter[k] == vwp.letter) { int PX = vwp.X; int PY = vwp.Y - k; //if (CheckPositionValidation.checkPositionValidation(index, "H", PX, PY) && CheckPositionValidation.checkPositionExist(index, "H", PX, PY) && CheckPositionValidation.checkcheckPositionCanBePlace(index, "H", PX, PY) && CheckPositionValidation.checkPositionIntersected(index, "H", PX, PY) && CheckPositionValidation.checkEachWordSpaceNotTouch(index, "H", PX, PY)) if (CheckPositionValidation.checkPositionValidation(index, "H", PX, PY)) { if (CheckPositionValidation.checkPositionExist(index, "H", PX, PY)) { if (CheckPositionValidation.checkcheckPositionCanBePlace(index, "H", PX, PY)) { if (CheckPositionValidation.checkPositionIntersected(index, "H", PX, PY)) { if (CheckPositionValidation.checkEachWordSpaceNotTouch(index, "H", PX, PY)) { addPosition(index, PX, PY, "H"); CreateCrozzle.TCSLNRSBWLforloop.RemoveAt(index); return(-1); } } } } } } } } for (int k = CreateCrozzle.TCSLNRSBWLforloop[index].wordlist.Length - 1; k >= 0; k--) { foreach (HorizontalWordPosition hwp in HWP) { if (hwp.letter == CreateCrozzle.TCSLNRSBWLforloop[index].letter[k]) { int PX = hwp.X - k; int PY = hwp.Y; //if (CheckPositionValidation.checkPositionValidation(index, "V", PX, PY) && CheckPositionValidation.checkPositionExist(index, "V", PX, PY) && CheckPositionValidation.checkcheckPositionCanBePlace(index, "V", PX, PY) && CheckPositionValidation.checkPositionIntersected(index, "V", PX, PY) && CheckPositionValidation.checkEachWordSpaceNotTouch(index, "V", PX, PY)) if (CheckPositionValidation.checkPositionValidation(index, "V", PX, PY)) { if (CheckPositionValidation.checkPositionExist(index, "V", PX, PY)) { if (CheckPositionValidation.checkcheckPositionCanBePlace(index, "V", PX, PY)) { if (CheckPositionValidation.checkPositionIntersected(index, "V", PX, PY)) { if (CheckPositionValidation.checkEachWordSpaceNotTouch(index, "V", PX, PY)) { addPosition(index, PX, PY, "V"); CreateCrozzle.TCSLNRSBWLforloop.RemoveAt(index); return(-1); } } } } } } } } return(index); }
private static void addPosition(int wordIndex, int IX, int IY, string path) { if (path == "H") { HWFE.Add(new HorizontalWordForExport(IX, IY, TCSLNRSBWLforloop[wordIndex].wordlist)); for (int i = 0; i < CreateCrozzle.TCSLNRSBWLforloop[wordIndex].letter.Length; i++) { int PX = IX; int PY = IY + i; int PYleft = IY - 1; int PYright = IY + CreateCrozzle.TCSLNRSBWLforloop[wordIndex].wordlist.Length; char PL = CreateCrozzle.TCSLNRSBWLforloop[wordIndex].letter[i]; string PW = CreateCrozzle.TCSLNRSBWLforloop[wordIndex].wordlist; if (position.GroupBy(x => x.X == IX && x.Y == IY + i).Count() > 1) { position.Add(new Position(PX, PY, PL, PW)); HWP.Add(new HorizontalWordPosition(PX, PY, PL, PW)); positionIntersect.Add(new PositionIntersect(PX, PY, PL, PW)); CheckPositionValidation.checkWordIntersectedTimes(path, PX, PY, PW); } else { position.Add(new Position(PX, PY, PL, PW)); positionNoRepeat.Add(new PositionNoRepeat(PX, PY, PL, PW)); HWP.Add(new HorizontalWordPosition(PX, PY, PL, PW)); } positionCanNotBePlace.Add(new PositionCanNotBePlace(PX, PYleft)); positionCanNotBePlace.Add(new PositionCanNotBePlace(PX, PYright)); //CheckPositionValidation.checkWordIntersectedTimes(path, PX, PY, PW); } } else if (path == "V") { VWFE.Add(new VerticalWordForExport(IX, IY, TCSLNRSBWLforloop[wordIndex].wordlist)); for (int i = 0; i < CreateCrozzle.TCSLNRSBWLforloop[wordIndex].letter.Length; i++) { int PX = IX + i; int PY = IY; char PL = CreateCrozzle.TCSLNRSBWLforloop[wordIndex].letter[i]; string PW = CreateCrozzle.TCSLNRSBWLforloop[wordIndex].wordlist; int PXtop = IX - 1; int PXbottom = IX + CreateCrozzle.TCSLNRSBWLforloop[wordIndex].wordlist.Length; if (position.GroupBy(x => x.X == IX + i && x.Y == IY).Count() > 1) { position.Add(new Position(PX, PY, PL, PW)); VWP.Add(new VerticalWordPosition(PX, PY, PL, PW)); positionIntersect.Add(new PositionIntersect(PX, PY, PL, PW)); CheckPositionValidation.checkWordIntersectedTimes(path, PX, PY, PW); } else { position.Add(new Position(PX, PY, PL, PW)); positionNoRepeat.Add(new PositionNoRepeat(PX, PY, PL, PW)); VWP.Add(new VerticalWordPosition(PX, PY, PL, PW)); } positionCanNotBePlace.Add(new PositionCanNotBePlace(PXtop, PY)); positionCanNotBePlace.Add(new PositionCanNotBePlace(PXbottom, PY)); //CheckPositionValidation.checkWordIntersectedTimes(path, PX, PY, PW); } } //CheckPositionValidation.checkWordIntersectedTimes(path); }