public string get_move(Board current_Board, int player) // gibt validen move und einfachen SPrung zurück { ComputerColor = player; Board = new Board(current_Board); tempmove = new List <string>(); tempjump = new List <string>(); //Liste aller validen Züge List <string> valid = new List <string>(); //Finaler move string final_move = ""; foreach (KeyValuePair <Piece, char> position in Board) { //Steinfarbe passt nicht zu Computerfarbe if (((player == 0) && (position.Value != 'b' && position.Value != 'B')) || ((player == 1 && (position.Value != 'w' && position.Value != 'W')))) { continue; } checkposition(position); } if (tempjump.Count == 0) { valid = tempmove; } else { //Überprüft Mehrfachsprung und gibt Liste aller validen Sprünge zurück (korrekte Syntax) foreach (string jump in tempjump) { valid = valid.Concat(jumps(drawing.StringToTuple(jump))).ToList(); } } //Zufälligen Valid Move auswählen Random Zufall = new Random(); final_move = valid[Zufall.Next(0, valid.Count)]; return(final_move); }
//Sortiert eine Liste mit Zügen nach einer Heuristik private List <string> Heuristic(List <string> valid, Board board, int player) { //output builds from best to worst, reverse from worst to best List <string> reverse = new List <string>(); List <string> output = new List <string>(); List <string> False = new List <string>(); //keinen Zug der gemerkten History wiederholen foreach (string move in valid) { if (history.Contains(move)) { reverse.Insert(0, move); } else { False.Add(move); } } valid = False; False = new List <string>(); //Dame bewegen foreach (string move in valid) { if (board[drawing.StringToTuple(move.Substring(0, 2))] == Convert.ToChar('B' + 21 * player)) { output.Add(move); } else { False.Add(move); } } valid = False; False = new List <string>(); //keine steine aus der grundreihe foreach (string move in valid) { if (move[1] == Convert.ToChar('1' + 8 * player)) { reverse.Insert(0, move); } else { False.Add(move); } } valid = False; False = new List <string>(); //moves that dont apply to any conditions are insertet between output and reverse output = output.Concat(valid).ToList(); output = output.Concat(reverse).ToList(); return(output); }
private List <Piece> Split(string move) //splits string to list of tuples { List <Piece> output = new List <Piece>(); string position = ""; for (int i = 0; i < move.Length; i += 3) { position = ""; position += move[i]; position += move[i + 1]; output.Add(drawing.StringToTuple(position)); } return(output); }