private List <cooridinate> get_random_coordinate_array(int size, int number_dots) { List <cooridinate> unique = new List <cooridinate>(); bool unique_flag = true; while (unique.Count < number_dots) { cooridinate coord = new cooridinate(); coord.x = (int)num.Next(0, size); coord.y = (int)num.Next(0, size); foreach (cooridinate test_coord in unique) { if ((test_coord.x != coord.x ^ test_coord.y != coord.y) || (test_coord.x != coord.x && test_coord.y != coord.y)) // XOR and AND { unique_flag = true; } else { unique_flag = false; break; } } if (unique_flag == true) { Console.WriteLine("Qualifying Coord: " + coord.x + " " + coord.y); unique_flag = false; unique.Add(coord); } } return(unique); }
public int computeManhattanDistance(cooridinate answer, cooridinate selection) { int xDist = (int)(Math.Abs(selection.x - answer.x)); int yDist = (int)(Math.Abs(selection.y - answer.y)); return(xDist + yDist); }
public float computeEuclideanDistance(cooridinate answer, cooridinate selection) { int xDist = (int)(Math.Abs(selection.x - answer.x)); int yDist = (int)(Math.Abs(selection.y - answer.y)); float hypotenuse = (float)(Math.Sqrt(Math.Pow(xDist, 2) + Math.Pow(yDist, 2))); return(hypotenuse); }
private void click_game_event(object sender, RoutedEventArgs e) { number_dots_clicked += 1; set_textblock_game_data(thisGame.size, number_dots_clicked, thisGame.user_game_score_euc, thisGame.user_game_score_man, thisGame.user_game_score_euc_combo, thisGame.user_game_score_man_combo, thisGame.show_button_duration); if (number_dots_clicked < thisGame.number_dots) { custom_button new_button = sender as custom_button; button_array[new_button.x, new_button.y].Template = Control_Template.Template; button_array[new_button.x, new_button.y].IsEnabled = false; cooridinate new_coord = new cooridinate(); new_coord.x = new_button.x; new_coord.y = new_button.y; selections.Add(new_coord); Console.WriteLine("Click: " + number_dots_clicked + " of " + thisGame.number_dots); } else { custom_button new_button = sender as custom_button; button_array[new_button.x, new_button.y].Template = Control_Template.Template; cooridinate new_coord = new cooridinate(); new_coord.x = new_button.x; new_coord.y = new_button.y; selections.Add(new_coord); List <cooridinate> answers2 = new List <cooridinate>(answers); List <cooridinate> answers3 = new List <cooridinate>(answers); List <cooridinate> answers4 = new List <cooridinate>(answers); List <cooridinate> selections2 = new List <cooridinate>(selections); List <cooridinate> selections3 = new List <cooridinate>(selections); List <cooridinate> selections4 = new List <cooridinate>(selections); thisGame.user_game_score_man = rowbasedMinManhattanDistance(answers2, selections2); thisGame.user_game_score_euc = rowbasedMinEuclideanDistance(answers, selections); thisGame.user_game_score_man_combo = combinationMinManhattanDistance(answers3, selections3); thisGame.user_game_score_euc_combo = combinationMinEuclideanDistance(answers4, selections4); thisGame.game_end = DateTime.Now; thisGame.game_play_duration = thisGame.game_start - thisGame.game_end; button_next_game.Visibility = Visibility.Visible; // games over go to the next game number_dots_clicked = 0; foreach (Button b in button_array) { b.IsEnabled = false; } set_game_data(); } }