/// <summary> /// Analyses the whole board. Runs unsorted list of scores for each line for each position. /// </summary> /// <returns>Line Analysis object with all lines analysed in the *unsorted* results property.</returns> /// <param name="player">Player number. The perspective of the analysis</param> internal RowAnalysis analyse_board(int player) { RowAnalysis r = new RowAnalysis(player, win_length); Console.WriteLine("height: {0} width: {1}", height, width); // check all horizontal rows & diagonals where appropriate for (int i = 0; i < height; i++) { r.analyse(extract_row(i * width), i * width, Direction.horizontal); Console.WriteLine("R" + i.ToString()); if (i <= height - win_length) { Console.WriteLine("DD:"); r.analyse(extract_diagonal_down(i * width), i * width, Direction.diagonal_down); } if (i >= win_length - 1) { Console.WriteLine("DU:"); r.analyse(extract_diagonal_up(i * width), i * width, Direction.diagonal_up); } } // check vertical rows & diagonal where appropriate for (int i = 0; i < width; i++) { r.analyse(extract_column(i), i, Direction.vertical); Console.WriteLine("C" + i.ToString()); if (i > 0 && i <= width - win_length) { Console.WriteLine("DB:"); r.analyse(extract_diagonal_down(i), i, Direction.diagonal_down); r.analyse(extract_diagonal_up((height - 1) * width + i), (height - 1) * width + i, Direction.diagonal_up); } } //r.Sort(); float best_rank = r.result[0].rank; int same_rank_count = 1; // check for equal ranks, and if so, random pick one for (int i = 1; i < r.result.Capacity; i++) { if (r.result[i].rank == best_rank) { same_rank_count++; } else { break; } } return(r); }
public static void Mainx(string[] args) { int[] row = { 1, 1, 0 }; RowAnalysis r = new RowAnalysis(1, 3); //r.analyse(row); Console.WriteLine(r.ToString()); }
// semi-intelligent.. will win, will block public void place_with_analyse() { int[] row = { 1, 1, 0 }; RowAnalysis r = new RowAnalysis(1, 3); //r.analyse(row); Console.WriteLine(r.ToString()); }