public Move Clone() { var m = new Move(); m.moves = new List<Point>(); for (int i = 0; i < moves.Count; i++) { m.moves.Add(new Point(this[i].X, this[i].Y)); } return m; }
public EvaluatedMove(int eval, Move move) { Eval = eval; Move = move; }
public List<Plansza[]> Parse(int count, int krok, int rank) { bool stop = false; Plansza p = new Plansza(); int pp = 200; int kkrok = 0; int nrListy = 0; int pionki = 0; while (true) { string s = ReadFileByLine(); if (s == null) return plansze; while ( stop && !s.StartsWith("[Event")) { s = ReadFileByLine(); } stop = false; //if (plansze.Count > pp) { //Console.WriteLine("{0}", plansze.Count); //pp = pp + 500; } if (plansze.Count == count) break; if (s.StartsWith("[Event")) { kkrok++; p = new Plansza(); p.rozpoczecie(); } else if (s.StartsWith("[Result")) { s = s.Remove(0, 9); if (s.StartsWith("1")) p.wynik = 1; else p.wynik = -1; } else if (s.StartsWith("[WhiteElo")) { s = s.Remove(0, 11); s = s.Remove(3); //bylo 4 int r = int.Parse(s); if (r < rank) { stop = true;}// continue; } } else if (s.StartsWith("[BlackElo")) { s = s.Remove(0, 11); s = s.Remove(3); //bylo 4 int r = int.Parse(s); if (r < rank) { stop = true; }// continue; } } else if (!s.StartsWith("[")) { //if (stop) continue; plansze.Add(new Plansza[(int)((24 / krok) - 1)]); pionki = 24; StringBuilder sb = new StringBuilder(); string tmp;// = ReadFileByLine(); while ((tmp = ReadFileByLine()) != "") { sb.Append(tmp + " "); //s.Insert(s.Length, tmp); //while (!tmp.StartsWith(@"a-h")) // tmp = tmp.Remove(0, 1); //if (tmp. } if (sb.ToString().Contains("{*}")) { stop = true; continue; } Regex rgx = new Regex("[0-9][.] | [0-9][0-9][.]"); foreach (string str in rgx.Split(sb.ToString())) { string[] ss = str.Split(' '); //if (ss[0] == "") ss. //if (ss.Length != 4) continue; for (int m = 0; m < ss.Length; m++) { if (ss[m] == "") continue; if (ss[m][0] == '0' || ss[m][0] == '1') { stop = true; break; } int k = 0; while (k + 2 < ss[m].Length && (ss[m][k + 2] == 'x' || ss[m][k + 2] == '-')) { char sdf = ss[m][k + 0]; int no = getNoFromLetter(sdf); int no2 = int.Parse(ss[m].Substring(k + 1, 1)) - 1; //p.pole[no, no2] = 1; sdf = ss[m][k + 3]; int no3 = getNoFromLetter(sdf); int no4 = int.Parse(ss[m].Substring(k + 4, 1)) - 1; //if (m == 1) p.pole[no3, no4] = 3; //else p.pole[no3, no4] = 2; Move m1 = new Move(new Point(no, 7 - no2)); m1.Add(new Point(no3, 7 - no4)); p.ExecuteMove(m1); //break; if (p.iloscPionkow() == pionki - krok) { Plansza r = p.Clone(); plansze[nrListy][24/krok-pionki/krok] = r; pionki = p.iloscPionkow(); //kkrok = 0; } else if (p.iloscPionkow() < pionki - krok) { } k = k + 3; } //if (kkrok == krok) //{ // Plansza r = p.Clone(); // plansze[nrListy].Add(r); kkrok = 0; //} //return plansze; } if (stop) break; } if (stop) { nrListy++; continue; } } } //plansze.RemoveAt(plansze.Count - 1); return plansze; }
/// <summary> /// Obsługuje klikniecie na planszy /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="p">Plansza</param> /// <param name="b">Bicia</param> /// <param name="gracz">Obecny gracz</param> /// <returns></returns> public void klikniecie(int x, int y, Plansza p, Bicia b, Gracz gracz, bool computer=false) { b.sprawdz_bicia(gracz, p); if (this.pole[x, y] == 0)//pierwszy klik { this.zerowanie(); if (p.pole[x, y] > 1) //jezeli w polu znajduje sie pionek { this.pole[x, y] = 1; // zaznaczam w ruchach miejsce //jezeli jest to pionek gracza 1 i jest jego ruch if (p.pole[x, y] == 2 && gracz.get_gracz() == 1) {//dodajemy do planszy ruchów 2 jak ruch bez bicia, 3 jak ruch z biciem if (x > 0 && y > 0 && p.pole[x - 1, y - 1] == 1 && !b.przymus) { this.pole[x - 1, y - 1] = 2; Move m = new Move(new Point(x, y)); m.moves.Add(new Point(x - 1, y - 1)); p.possibleMoves.Add(m); } if (x < 7 && y > 0 && p.pole[x + 1, y - 1] == 1 && !b.przymus) { this.pole[x + 1, y - 1] = 2; Move m = new Move(new Point(x, y)); m.moves.Add(new Point(x + 1, y - 1)); p.possibleMoves.Add(m); } if (x > 1 && y > 1 && (p.pole[x - 1, y - 1] == 3 || p.pole[x - 1, y - 1] == 5) && p.pole[x - 2, y - 2] == 1) { this.pole[x - 2, y - 2] = 3; Move m = new Move(new Point(x, y)); m.moves.Add(new Point(x - 2, y - 2)); p.possibleBeats.Add(m); } if (x < 6 && y > 1 && (p.pole[x + 1, y - 1] == 3 || p.pole[x + 1, y - 1] == 5) && p.pole[x + 2, y - 2] == 1) { this.pole[x + 2, y - 2] = 3; Move m = new Move(new Point(x, y)); m.moves.Add(new Point(x + 2, y - 2)); p.possibleBeats.Add(m); } if (x > 1 && y < 6 && (p.pole[x - 1, y + 1] == 3 || p.pole[x - 1, y + 1] == 5) && p.pole[x - 2, y + 2] == 1) { this.pole[x - 2, y + 2] = 3; Move m = new Move(new Point(x, y)); m.moves.Add(new Point(x - 2, y + 2)); p.possibleBeats.Add(m); } if (x < 6 && y < 6 && (p.pole[x + 1, y + 1] == 3 || p.pole[x + 1, y + 1] == 5) && p.pole[x + 2, y + 2] == 1) { this.pole[x + 2, y + 2] = 3; Move m = new Move(new Point(x, y)); m.moves.Add(new Point(x + 2, y +2)); p.possibleBeats.Add(m); } } //jezeli jest to pionek racza 2 else if (p.pole[x, y] == 3 && gracz.get_gracz() == 2) { if (x > 0 && y < 7 && p.pole[x - 1, y + 1] == 1 && !b.przymus) { this.pole[x - 1, y + 1] = 2; Move m = new Move(new Point(x, y)); m.moves.Add(new Point(x - 1, y + 1)); p.possibleMoves.Add(m); } if (x < 7 && y < 7 && p.pole[x + 1, y + 1] == 1 && !b.przymus) { this.pole[x + 1, y + 1] = 2; Move m = new Move(new Point(x, y)); m.moves.Add(new Point(x + 1, y + 1)); p.possibleMoves.Add(m); } if (x > 1 && y < 6 && (p.pole[x - 1, y + 1] == 2 || p.pole[x - 1, y + 1] == 4) && p.pole[x - 2, y + 2] == 1) { this.pole[x - 2, y + 2] = 3; Move m = new Move(new Point(x, y)); m.moves.Add(new Point(x - 2, y + 2)); p.possibleBeats.Add(m); } if (x < 6 && y < 6 && (p.pole[x + 1, y + 1] == 2 || p.pole[x + 1, y + 1] == 4) && p.pole[x + 2, y + 2] == 1) { this.pole[x + 2, y + 2] = 3; Move m = new Move(new Point(x, y)); m.moves.Add(new Point(x + 2, y + 2)); p.possibleBeats.Add(m); } if (x > 1 && y > 1 && (p.pole[x - 1, y - 1] == 2 || p.pole[x - 1, y - 1] == 4) && p.pole[x - 2, y - 2] == 1) { this.pole[x - 2, y - 2] = 3; Move m = new Move(new Point(x, y)); m.moves.Add(new Point(x - 2, y - 2)); p.possibleBeats.Add(m); } if (x < 6 && y > 1 && (p.pole[x + 1, y - 1] == 2 || p.pole[x + 1, y - 1] == 4) && p.pole[x + 2, y - 2] == 1) { this.pole[x + 2, y - 2] = 3; Move m = new Move(new Point(x, y)); m.moves.Add(new Point(x + 2, y - 2)); p.possibleBeats.Add(m); } } //jezeli jest to damka gracza 1 lub gracza 2 i to jest jego ruch else if ((p.pole[x, y] == 4 && gracz.get_gracz() == 1) || (p.pole[x, y] == 5 && gracz.get_gracz() == 2)) { int i = 0; int j = 0; int add = (gracz.get_gracz() == 1) ? 1 : 0; while (!b.przymus && x + i > 0 && y + j > 0)//markuje na 2 te pola na których może stanąć { if (p.pole[x + i - 1, y + j - 1] == 1)//puste pole na planszy { this.pole[x + i - 1, y + j - 1] = 2; Move m = new Move(new Point(x, y)); m.moves.Add(new Point(x + i - 1, y + j - 1)); p.possibleMoves.Add(m); --i; --j; } else break; } i = 0; j = 0; while (!b.przymus && x + i < 7 && y + j > 0) { if (p.pole[x + i + 1, y + j - 1] == 1) { this.pole[x + i + 1, y + j - 1] = 2; Move m = new Move(new Point(x, y)); m.moves.Add(new Point(x + i + 1, y + j - 1)); p.possibleMoves.Add(m); ++i; --j; } else break; } i = 0; j = 0; while (!b.przymus && x + i > 0 && y + j < 7) { if (p.pole[x + i - 1, y + j + 1] == 1) { this.pole[x + i - 1, y + j + 1] = 2; Move m = new Move(new Point(x, y)); m.moves.Add(new Point(x + i - 1, y + j + 1)); p.possibleMoves.Add(m); --i; ++j; } else break; } i = 0; j = 0; while (!b.przymus && x + i < 7 && y + j < 7) { if (p.pole[x + i + 1, y + j + 1] == 1) { this.pole[x + i + 1, y + j + 1] = 2; Move m = new Move(new Point(x, y)); m.moves.Add(new Point(x + i + 1, y + j + 1)); p.possibleMoves.Add(m); ++i; ++j; } else break; } bool bij = false; i = 0; j = 0; while (x + i > 0 && y + j > 0)//jak jest bicie markuje na 3 pola na których może stanąć po biciu { if (p.pole[x + i - 1, y + j - 1] == 1) { if (bij) { this.pole[x + i - 1, y + j - 1] = 3; Move m = new Move(new Point(x, y)); m.moves.Add(new Point(x + i - 1, y + j - 1)); p.possibleBeats.Add(m); } --i; --j; } else if (p.pole[x + i - 1, y + j - 1] == 2 + add || p.pole[x + i - 1, y + j - 1] == 4 + add) { if (!bij) { bij = true; --i; --j; } else break; } else break; } bij = false; i = 0; j = 0; while (x + i < 7 && y + j > 0) { if (p.pole[x + i + 1, y + j - 1] == 1) { if (bij) { this.pole[x + i + 1, y + j - 1] = 3; Move m = new Move(new Point(x, y)); m.moves.Add(new Point(x + i + 1, y + j - 1)); p.possibleBeats.Add(m); } ++i; --j; } else if (p.pole[x + i + 1, y + j - 1] == 2 + add || p.pole[x + i + 1, y + j - 1] == 4 + add) { if (!bij) { bij = true; ++i; --j; } else break; } else break; } bij = false; i = 0; j = 0; while (x + i > 0 && y + j < 7) { if (p.pole[x + i - 1, y + j + 1] == 1) { if (bij) { this.pole[x + i - 1, y + j + 1] = 3; Move m = new Move(new Point(x, y)); m.moves.Add(new Point(x + i - 1, y + j + 1)); p.possibleBeats.Add(m); } --i; ++j; } else if (p.pole[x + i - 1, y + j + 1] == 2 + add || p.pole[x + i - 1, y + j + 1] == 4 + add) { if (!bij) { bij = true; --i; ++j; } else break; } else break; } bij = false; i = 0; j = 0; while (x + i < 7 && y + j < 7) { if (p.pole[x + i + 1, y + j + 1] == 1) { if (bij) { this.pole[x + i + 1, y + j + 1] = 3; Move m = new Move(new Point(x, y)); m.moves.Add(new Point(x + i + 1, y + j + 1)); p.possibleBeats.Add(m); } ++i; ++j; } else if (p.pole[x + i + 1, y + j + 1] == 2 + add || p.pole[x + i + 1, y + j + 1] == 4 + add) { if (!bij) { bij = true; ++i; ++j; } else break; } else break; } } // this.wyswietlanie(); } old_x = x; old_y = y; }/* else if (this.pole[x,y] == 1) { this.zerowanie(); }*/ else if (this.pole[x, y] == 2)//wykonanie ruchu, bo na pole można się ruszyć bez bicia { p.pole[x, y] = p.pole[old_x, old_y]; p.pole[old_x, old_y] = 1; this.zerowanie(); p.zamien_pionki_na_damki(gracz); // gracz.zmiana_gracza(computer); } else if (this.pole[x, y] == 3)//wykonanie bicia { p.pole[x, y] = p.pole[old_x, old_y]; int i = old_x; int j = old_y; int add_i = (old_x < x) ? 1 : -1; int add_j = (old_y < y) ? 1 : -1; int kill_x = i + add_i; int kill_y = j + add_j; while (kill_x != x && kill_y != y) { p.pole[kill_x, kill_y] = 1; kill_x += add_i; kill_y += add_j; // System.out.println("kiler : " + kill_x + " " + kill_y); } p.pole[old_x, old_y] = 1; this.zerowanie(); b.sprawdz_bicia(gracz, p, x, y);//zmiana gracza po biciu if (!b.przymus) { p.zamien_pionki_na_damki(gracz); // gracz.zmiana_gracza(computer); } else//kolejny ruch { klikniecie(x, y, p, b, gracz,computer); } } b.sprawdz_bicia(gracz, p); }
public static void MoveChecker(Move m, Checker[] board, int size) { MoveChecker(m.From, m.To, board, size); }