public void checkStatus() { // ריצה על כל השכנים של הכרטיסים המופיעים על הלוח תוך בדיקה איזה רצף יצור כל אחד for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { if (clGlobal.boardStatus[i, j] == 1) { checkSequence(i, j - 1, listCheck); checkSequence(i, j + 1, listCheck); checkSequence(i - 1, j, listCheck); checkSequence(i + 1, j, listCheck); checkSequence(i + 1, j - 1, listCheck); checkSequence(i + 1, j + 1, listCheck); checkSequence(i - 1, j - 1, listCheck); checkSequence(i - 1, j + 1, listCheck); } } } checkPoint temp = new checkPoint(); temp.tzover = 0; temp.PlayerMaxLength = 5; // ריצה על הנחת הכרטיסים על האורך המקסימלי while (searchPlaceForTheMaxLength(ref temp, false) != 2 && listCheck.Count != 0) { ; } }
private void addToList(int iMatrix, int jMatrix, int cnt, int tzover, List <checkPoint> listTemp) { checkPoint c = new checkPoint(); c.i = iMatrix; c.j = jMatrix; c.lenght = cnt; c.tzover = tzover; listTemp.Add(c); }
public checkPoint checkAllNeighboursForAllList(checkPoint l, int cardNum) { //ריצה על הקלפים של המחשב //הפונקציה מחזירה את הקלף הכי מתאים למקום //cardNum = הוא מספר הכרטיס בפאנל הכרטיסים של המחשב שאיננו רוצים לבדוק, כיוון שזהו הקלף שיונח במהלך זה //cardNum = -1 -> אם רוצים לבדוק את כל הקלפים ערכו int j = 0; int max = 0; int maxi = -1; int rotate = 0; int maxr = 0; for (int i = 0; i < clGlobal.computerCardsNum; i++) { if (cardNum != i) { //l.numOfRotate = 0; board[l.i, l.j].saveCardValues(computerCards[i].rowInSavepic); if (board[l.i, l.j].checkBorder(l.i, l.j) == true) { for (j = 0, rotate = 0; j < 3 && board[l.i, l.j].checkAllNeighbours(l.i, l.j, board[l.i, l.j].matValues) == false; rotate++, j++) { board[l.i, l.j].RotateMatValues(); } if (board[l.i, l.j].checkAllNeighbours(l.i, l.j, board[l.i, l.j].matValues) == true) { if (board[l.i, l.j].matValues[1][1] > max)//כאן צריך להוסיף בדיקה לגבי הכרטיס האפס { max = board[l.i, l.j].matValues[1][1]; maxi = i; maxr = rotate; } } } } } //לא נמצא קלף מתאים למקום if (maxi == -1) { l.numOfcard = -1; } l.tzover += max; l.numOfcard = maxi; l.numOfRotate = maxr; return(l); // board[l.i, l.j].BackgroundImage = computerCards[l.numOfcard].BackgroundImage; }
private int searchPlacePlayer(ref checkPoint temp, Boolean notFoundGoodLength) { //מציאת האורך המקסימלי ברשימת המשבצות הנתונה int maxLeng = 0; foreach (var l in listPlayer) { if (l.lenght > maxLeng && ((l.lenght != 4 && notFoundGoodLength == false) || notFoundGoodLength == true)) { maxLeng = l.lenght; } } if (maxLeng == 0) { maxLeng = 4; } //ריצה על המשבצות הנותנות את האורך הארוך for (int i = 0; i < listPlayer.Count;) { if (listPlayer[i].lenght == maxLeng) { listPlayer[i] = checkAllNeighboursForAllPlayerList(listPlayer[i]); //חיפוש קלף מתאים למיקום הנוכחי מקלפי המחשב if (listPlayer[i].numOfcard == -1) // לא נמצא קלף מתאים למיקום הנוכחי { listPlayer.Remove(listPlayer[i]); } else { if (listPlayer[i].tzover > temp.tzover) //בדיקה אם הניקוד המצטבר של הקלף הנוכחי גבוה יותר { temp = listPlayer[i]; } i++; } } else { i++; } } if (temp.lenght != 0) { listPlayer.Clear(); } return(temp.lenght); //החזרת האורך הארוך ביותר שיכול השקחן ליצור אם יונח הקלף }
public checkPoint checkAllNeighboursForAllPlayerList(checkPoint l) { //ריצה על הקלפים של המחשב //הפונקציה מחזירה את הקלף הכי מתאים למקום int j = 0; int max = 0; int maxi = -1; int rotate = 0; int maxr = 0; for (int i = 0; i < clGlobal.playerCardsNum; i++) { //l.numOfRotate = 0; board[l.i, l.j].saveCardValues(playerCards[i].rowInSavepic); if (board[l.i, l.j].checkBorder(l.i, l.j) == true) { for (j = 0, rotate = 0; j < 3 && board[l.i, l.j].checkAllNeighbours(l.i, l.j, board[l.i, l.j].matValues) == false; rotate++, j++) { board[l.i, l.j].RotateMatValues(); } if (j < 3) { if (board[l.i, l.j].matValues[1][1] > max)//כאן צריך להוסיף בדיקה לגבי הכרטיס האפס { max = board[l.i, l.j].matValues[1][1]; maxi = i; maxr = rotate; } } } } //לא נמצא קלף מתאים למקום if (maxi == -1) { l.numOfcard = -1; } l.tzover += max; l.numOfcard = maxi; l.numOfRotate = maxr; return(l); // board[l.i, l.j].BackgroundImage = computerCards[l.numOfcard].BackgroundImage; }
public checkPoint checkPlayerStatus() { // ריצה על כל השכנים של הכרטיסים המופיעים על הלוח תוך בדיקה איזה רצף יצור כל אחד for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { if (clGlobal.boardStatus[i, j] == 1) { checkSequence(i, j - 1, listPlayer); checkSequence(i, j + 1, listPlayer); checkSequence(i - 1, j, listPlayer); checkSequence(i + 1, j, listPlayer); checkSequence(i + 1, j - 1, listPlayer); checkSequence(i + 1, j + 1, listPlayer); checkSequence(i - 1, j - 1, listPlayer); checkSequence(i - 1, j + 1, listPlayer); } } } checkPoint temp = new checkPoint(); temp.tzover = 0; temp.lenght = 0; // (!=4)ריצה על הנחת הכרטיסים על האורך המקסימלי while (searchPlacePlayer(ref temp, false) != 2 && listPlayer.Count != 0) { ; } //במקרה שלא מצא להניח שום דבר שינסה לחפש רצף של ארבע if (listPlayer.Count != 0) { searchPlacePlayer(ref temp, true); } return(temp); }
private int searchPlaceForTheMaxLength(ref checkPoint temp, Boolean notFoundGoodLength) { //מציאת האורך המקסימלי ברשימת המשבצות הנתונה int maxLeng = 0; foreach (var l in listCheck) { if (l.lenght > maxLeng) { maxLeng = l.lenght; } } if (maxLeng == 0) //אין קלפים להניח -> הוספת קלף לפאנל { dlA(); } //ריצה על המשבצות הנותנות את האורך הארוך for (int i = 0; i < listCheck.Count;) { if (listCheck[i].lenght == maxLeng) { listCheck[i] = checkAllNeighboursForAllList(listCheck[i], -1); //חיפוש קלף מתאים למיקום הנוכחי מקלפי המחשב if (listCheck[i].numOfcard == -1) // לא נמצא קלף מתאים למיקום הנוכחי { listCheck.Remove(listCheck[i]); } else { //בדיקה מה יהיה המהלך הבא של השחקן - מהו האורך המקסימלי שיכול ליצור אם יונח הקלף הזה clGlobal.boardStatus[listCheck[i].i, listCheck[i].j] = 1; //סימון המקום כתפוס-מצב הלוח אם יתבצע מהלך זה checkPoint res = checkPlayerStatus(); //אורך מהלך השחקן if (res.lenght < 5) { //אם האורך המקסימלי 4 ולשחקן אין להשלים ל-5 -> בדיקה אם למחשב יהיה להשלים ל-5 במהלך הבא //אם כן -יונח, אם לא - לא יונח if (checkFourInLine(res.i, res.j) == true) { bool compNext = CompNextMovementLength(listCheck[i].numOfcard); //בדיקה אם המחשב יוכל להשלים רצף במהלך הבא clGlobal.boardStatus[listCheck[i].i, listCheck[i].j] = 0; if (compNext == true) { if (listCheck[i].tzover > temp.tzover) { temp = listCheck[i]; temp.PlayerMaxLength = res.lenght; } } else { listCheck.Remove(listCheck[i]); } } else { if (res.lenght < temp.PlayerMaxLength) //בדיקה אם הניקוד המצטבר של הקלף הנוכחי גבוה יותר { temp = listCheck[i]; temp.PlayerMaxLength = res.lenght; } else if (res.lenght == temp.PlayerMaxLength) { if (listCheck[i].tzover > temp.tzover) { temp = listCheck[i]; temp.PlayerMaxLength = res.lenght; } } clGlobal.boardStatus[listCheck[i].i, listCheck[i].j] = 0; } } else //res==5 { clGlobal.boardStatus[listCheck[i].i, listCheck[i].j] = 0; listCheck.Remove(listCheck[i]); i--; //חזרה לאותו מקום ברשימה } i++; } } else { i++; } } //הנחת הכרטיס //if (temp.tzover > 0) if (temp.lenght > 0) { board[temp.i, temp.j].placeFlag = true; //סימון המקום כתפוס board[temp.i, temp.j].rotateFlag = false; //סימון המקום כלא ניתן לסיבוב clGlobal.boardStatus[temp.i, temp.j] = 1; //הבהוב והורדת הכרטיסים בעת יצירת חמישיה Image b = computerCards[temp.numOfcard].BackgroundImage; board[temp.i, temp.j].saveCardValues(computerCards[temp.numOfcard].rowInSavepic); if (temp.numOfRotate != 0) { for (int k = 0; k < temp.numOfRotate; k++) { board[temp.i, temp.j].RotateMatValues(); b = utilities.RotateImage(b, 90); //Rotate Sender PicBoard } temp.numOfRotate = 0; } board[temp.i, temp.j].BackgroundImage = b; dlPnlColor(); if (maxLeng == 5) { board[temp.i, temp.j].checkSequence(temp.i, temp.j, 1); } dl(temp.numOfcard); //צבירת נקודות של הרצף שנוצר //getComputerScores(temp.i, temp.j); listCheck.Clear(); } else { if (listCheck.Count == 0) //אין קלפים להניח -> הוספת קלף לפאנל { dlA(); } } return(maxLeng); }