#!/pkg/gnu/bin/gawk -f BEGIN { # this should only get called once # it reads from a file first_move.sav. This file # should be in place with a 0 (zero) and a carriage return # then when Init_Game() runs the zero is changed to a 1 # Init_Game() #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # utility functions that get called every turn if (first_move != 1) Call_Restore_Info() Recent_Results() Update_Our_Locations() Revealed_Our_Piece() Update_His_Locations() Revealed_Enemy_Piece() print "my_move_action = " my_move_action > "/dev/stderr" not_a_flag_bomb_f() Update_Flag_Prob() update_bomb_prob() print "max_probability_of_bomb= " max_probability_of_bomb > "/dev/stderr" Calc_Max_Prob_Of_Flag() Choose_Move() Save_Info() print "done" >> "log.sav" } #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # # #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #DEFENSIVE_MOVE: returns a weight for the best defensive move out of all our pieces, scans 2 to 3 moves away, #weight ranges from 0...99 global variables defense_our_piece, defense_enemy_piece hold the indices involved #in the best move function defensive_move( current_loc, arr, max_dist, max_weight, row_col, r, c, start_row, start_col, end_row, end_col, n, type, weight) { print "Defensive Move" > "/dev/stderr" max_dist = 5 max_weight = 0 for(i = 0; i <= 39; i++) { current_loc = our_location_indx[i] #print our_location_indx[i] >> "log.sav" if (current_loc == "") { continue } split(current_loc, row_col, ":") start_row = row_col[1] - 2 end_row = row_col[1] + 2 start_col = row_col[2] - 2 end_col = row_col[2] + 2 for(r = start_row; r <= end_row; r++) { for(c = start_col; c <= end_col; c++) { if ( r < 1 || c < 1 ) { continue } if ( r >= 5 ) { continue } if ( row_col[1] > 5 ) { continue } if ( r == row_col[1] && c == row_col[2] ) { continue } #print "looking at row " r " col " c "for enemy pieces" > "/dev/stderr" n = find_index(r, c, enemy_location_indx) if (enemy_location_indx[n] == "-1:-1") { continue } if ( n >= 0 ) { if ( our_rank_indx[i] == "B" || our_rank_indx[i] == "*" ) { continue } m = free_path_enemy(defense_temp_a, current_loc, (r ":" c)) if ( m > 2 || m < 0) { continue } type = higher_lower_unknown(our_rank_indx[i],n) if ( type == 0 ) { if ( (r == start_row || r == end_row) || (c == start_col || c == end_col) ) { weight = 10 } else if ( (r == start_row + 1 || r == end_row - 1) || (c == start_col + 1 || c == end_col - 1 ) ) { weight = 15 } } if ( type == 1 ) { if ( (r == start_row || r == end_row) || (c == start_col || c == end_col) ) { weight = 20 } if ( (r == start_row + 1 || r == end_row - 1) || (c == start_col + 1 || c == end_col - 1 ) ) { weight = 30 } } if ( type == -1 ) { if ( (r == start_row || r == end_row) || (c == start_col || c == end_col) ) { weight = 5 } if ( (r == start_row + 1 || r == end_row - 1) || (c == start_col + 1 || c == end_col - 1 ) ) { weight = 7 } } if ( type == -2 ) { if ( (r == start_row || r == end_row) || (c == start_col || c == end_col) ) { weight = 2 } if ( (r == start_row + 1 || r == end_row - 1) || (c == start_col + 1 || c == end_col - 1 ) ) { weight = 4 } } if ( type == 2 ) { if ( (r == start_row || r == end_row) || (c == start_col || c == end_col) ) { weight = 40 } if ( (r == start_row + 1 || r == end_row - 1) || (c == start_col + 1 || c == end_col - 1 ) ) { weight = 50 } } combined = r ":" c #print "combined= " combined >> "log.sav" curr_dist = dist_to_our_flag(combined) free = free_path(defense_temp_b, combined, our_location_indx[flag_indx], 1) if (curr_dist < max_dist ) { weight = weight + 40 } if(curr_dist < 4) { weight = weight + 25 } #check if enemy is making a path to our flag else if ( eccentricity(curr_dist, free) <= 2 ) { weight = weight + 20 } if ( weight > max_weight ){ max_weight = weight defense_our_piece = i defense_enemy_piece = n defense_move_to = defense_temp_a[1] } } } } } return max_weight } #+++++++++++++++++ #FIND_INDEX: finds the index of the piece at row "r" and column "c" in array "arr" function find_index(r, c, arr, i, rowcol) { rowcol = r ":" c for(i = 0; i <= 39; i++ ) { if(arr[i] == rowcol) { return i } } return -1 } #DIST_TO_OUR_FLAG: finds the distance in moves, using optimal_path, curr is "row:col" specification #flag_indx is a global variable as well as our_location_indx function dist_to_our_flag(curr, arr) { return optimal_path(arr, curr, our_location_indx[flag_indx]) } #DIST_TO_THEIR_FLAG: finds the distance in moves, using optimal_path, curr is "row:col" function dist_to_their_flag(curr, arr) { return optimal_path(arr, curr, max_probability_of_flag) } #OPTIMAL_PATH: stores the best path from "start" to "end" in array "arr", ignores pieces on board, but does avoid water and does #not go off the board, "arr" starts at index 1, and holds "up","down","left", or "right". typical call: optimal_path(a, "4:3","7:3") function optimal_path(arr, start, end, been, went, curr, temp, possible, triangulate, start_pnt, end_pnt, r, s, t, u, b, c, best1, best2, worst1, worst2, v, backwards, n ) { ++curr been[start] arr[curr] = "" best1= ""; best2 = ""; worst1 = ""; worst2 = "" possible["up"] = 1 possible["down"] = 1 possible["left"] = 1 possible["right"] = 1 split(start, start_pnt, ":") split(end, end_pnt, ":") if ( start == end ) { delarray(been) return 0 } if ( went == "up" ) { backwards = "down" } if ( went == "down" ) { backwards = "up" } if ( went == "left" ) { backwards = "right" } if ( went == "right" ) { backwards = "left" } if ( backwards != "" ) { possible[backwards] = 0 } if(water(start_pnt[1], start_pnt[2], "left") == 1) { possible["left"] = 0 } if(water(start_pnt[1], start_pnt[2], "right") == 1) { possible["right"] = 0 } if(water(start_pnt[1], start_pnt[2], "up") == 1) { possible["up"] = 0 } if(water(start_pnt[1], start_pnt[2], "down") == 1) { possible["down"] = 0 } triangulate[1] = "up" ":" (end_pnt[1] - (start_pnt[1] + 1) )^2 + (end_pnt[2] - start_pnt[2] )^2 triangulate[2] = "down" ":" (end_pnt[1] - (start_pnt[1] - 1) )^2 + (end_pnt[2] - start_pnt[2] )^2 triangulate[3] = "right" ":" (end_pnt[1] - start_pnt[1])^2 + (end_pnt[2] - (start_pnt[2] + 1) )^2 triangulate[4] = "left" ":" (end_pnt[1] - start_pnt[1])^2 + (end_pnt[2] - (start_pnt[2] - 1) )^2 sort(triangulate, 4) split(triangulate[1], r, ":") best1 = r[1] split(triangulate[2], s, ":") best2 = s[1] split(triangulate[3], t, ":") worst1 = t[1] split(triangulate[4], u, ":") worst2 = u[1] temp = find_next(best1, start_pnt) if ( temp in been ) { possible[best1] = 0 } temp = find_next(best2, start_pnt) if ( temp in been ) { possible[best2] = 0 } temp = find_next(worst1, start_pnt) if ( temp in been ) { possible[worst1] = 0 } temp = find_next(worst2, start_pnt) if ( temp in been ) { possible[worst2] = 0 } if (s[2] == t[2] && possible[s[1]] == 1 && possible[t[1]] == 1) { for ( v in been ) { b[v] = "" c[v] = "" } start1 = find_next(s[1], start_pnt) went1 = s[1] l = optimal_path(x, start1, end, b, went1) start2 = find_next(t[1], start_pnt) went2 = t[1] k = optimal_path(y, start2, end, c, went2) delarray(b) delarray(c) delarray(x) delarray(y) if ( k < l) { temp = best2 best2 = worst1 worst1 = temp } } if(possible[best1] == 1 ) { arr[curr] = best1 } else if(possible[best2] == 1 ) { arr[curr] = best2 } else if ( possible[worst1] == 1 ) { arr[curr] = worst1 } else if ( possible[worst2] == 1) { arr[curr] = worst2 } if ( arr[curr] != "" ) { went = arr[curr] if ( arr[curr] == "up" ) { start = (start_pnt[1] + 1) ":" start_pnt[2] } if ( arr[curr] == "down" ) { start = (start_pnt[1] - 1) ":" start_pnt[2] } if ( arr[curr] == "left" ) { start = start_pnt[1] ":" (start_pnt[2] - 1) } if ( arr[curr] == "right" ) { start = start_pnt[1] ":" (start_pnt[2] + 1) } arr[curr] = start n = 1 + optimal_path(arr, start, end, been, went, curr) delarray(been) return n } else { #print "unsuccessful path" > "/dev/stderr" delarray(been) return 0 } } #SORT: helper function for optimal path, utilizes insertion sort, sorts values like "down:4" according to #their numeric value function sort(a, n, tempa, tempb,j, value, i) { for ( j = 2; j <= n; j++ ) { split (a[j], tempa, ":") key = tempa[2] i = j - 1 split(a[i], tempb, ":") while ( i > 0 && tempb[2] > key ) { a[i + 1] = a[i] i = i - 1 split(a[i], tempb, ":") } a[i + 1 ] = tempa[1] ":" tempa[2] } } #FIND_NEXT: takes direction "a" and a start point and finds the "row:col" where that piece would end up #implemented because I was sick of writing it in a hundred places function find_next(a, start_pnt) { if ( a == "up" ) { return (start_pnt[1] + 1) ":" start_pnt[2] } if ( a == "down" ) { return (start_pnt[1] - 1) ":" start_pnt[2] } if ( a == "left") { return start_pnt[1] ":" (start_pnt[2] - 1) } if ( a == "right") { return start_pnt[1] ":" (start_pnt[2] + 1) } } #WATER: takes a row, col and direction and returns whether or not that would result in a your # piece taking a swim function water(r, c, dir, i) { if ( dir == "up" ) { r = r + 1 } else if ( dir == "down" ) { r = r - 1 } else if ( dir == "left" ) { c = c - 1 } else if ( dir == "right") { c = c + 1 } if ( (r == 5 || r == 6) && (c == 3 || c == 4 || c == 7 || c == 8) ) { #print "In hazard" return 1 } } #OPEN_SPACE: basically illegal_move that also checks for enemy pieces function open_space(curr_row, curr_col, direction, num_spaces, end, x, new_row_col) { #direction 1(up), 2(left), 3 (right), 4(down) if (direction == 2) { new_col = curr_col - num_spaces new_row = curr_row } if (direction == 3) { new_col = curr_col + num_spaces new_row = curr_row } if (direction == 1) { new_row = curr_row + num_spaces new_col = curr_col } if (direction == 4) { new_row = curr_row - num_spaces new_col = curr_col } if (new_row > 10 || new_row < 1 || new_col > 10 || new_col < 1) { return 1 } if ( (new_row == 5 || new_row == 6) && (new_col == 3 || new_col == 4 || new_col == 7 || new_col == 8) ) { return 1 } # check if attacking friendly # new_row_col = new_row":"new_col for (x=0; x <= 39; x++) { if (new_row_col == our_location_indx[x]) { return 1 } } if ( new_row_col == end ) { return 0 } #added by Greg 10/24 #checks if attacking enemy for ( x=0; x <= 39; x++) { if ( new_row_col == enemy_location_indx[x]) { return 1 } } } #FREE_PATH: checks for a free path from "start" to "end" which are "row:col" specifications, "arr" holds #the path in strings "up", "down", "left", or "right", e.g. arr[1] = "left". Specifying "tol" will allow you #to set how many spacesfrom the target the path can end and still be successful, e.g. tol=3 will allow the #path to end three moves away from the target and be successful. A typical call to this function would be #free_path(somearray, "somerow:somecol", "targetrow:targetcol", sometolerance) function free_path(arr, start, end, tol, been, went, curr, temp, possible, triangulate, start_pnt, end_pnt, v, best1, best2, worst1, worst2, r, s, t, u, b, c, val, backwards, arr2, n ) { #print start ++curr been[start] arr[curr] = "" best1= ""; best2 = ""; worst1 = ""; worst2 = "" backwards = "" possible["up"] = 1 possible["down"] = 1 possible["left"] = 1 possible["right"] = 1 split(start, start_pnt, ":") split(end, end_pnt, ":") n = optimal_path(arr2, start, end, temparr, went) if ( start == end || n <= tol) { #print "successful path" > "/dev/stderr" delarray(been) return n } delarray(temparr) delarray(arr2) if ( went == "up" ) { backwards = "down" } if ( went == "down" ) { backwards = "up" } if ( went == "left" ) { backwards = "right" } if ( went == "right" ) { backwards = "left" } if ( backwards != "" ) { possible[backwards] = 0 } if(open_space(start_pnt[1], start_pnt[2], 2, 1, end) == 1) { possible["left"] = 0 } if(open_space(start_pnt[1], start_pnt[2], 3, 1, end) == 1) { possible["right"] = 0 } if(open_space(start_pnt[1], start_pnt[2], 1, 1, end) == 1) { possible["up"] = 0 } if(open_space(start_pnt[1], start_pnt[2], 4, 1, end) == 1) { possible["down"] = 0 } triangulate[1] = "up" ":" (end_pnt[1] - (start_pnt[1] + 1) )^2 + (end_pnt[2] - start_pnt[2] )^2 triangulate[2] = "down" ":" (end_pnt[1] - (start_pnt[1] - 1) )^2 + (end_pnt[2] - start_pnt[2] )^2 triangulate[3] = "right" ":" (end_pnt[1] - start_pnt[1])^2 + (end_pnt[2] - (start_pnt[2] + 1) )^2 triangulate[4] = "left" ":" (end_pnt[1] - start_pnt[1])^2 + (end_pnt[2] - (start_pnt[2] - 1) )^2 sort(triangulate, 4) split(triangulate[1], r, ":") best1 = r[1] split(triangulate[2], s, ":") best2 = s[1] split(triangulate[3], t, ":") worst1 = t[1] split(triangulate[4], u, ":") worst2 = u[1] #print best1 " " possible[best1] " " best2 " " possible[best2] " " worst1 " " possible[worst1] " " worst2 " " possible[worst2] > "/dev/stderr" temp = find_next(best1, start_pnt) if ( temp in been ) { possible[best1] = 0 } if ( dead_end(temp, end) == 1 ) { possible[best1] = 0 } if (temp == end ) { possible[best1] = 1 } temp = find_next(best2, start_pnt) if ( temp in been ) { possible[best2] = 0 } if ( dead_end(temp, end) == 1 ) { possible[best2] = 0 } if (temp == end ) { possible[best2] = 1 } temp = find_next(worst1, start_pnt) if ( temp in been ) { possible[worst1] = 0 } if ( dead_end(temp, end) == 1) { possible[worst1] = 0 } if (temp == end ) { possible[worst1] = 1 } temp = find_next(worst2, start_pnt) if ( temp in been ) { possible[worst2] = 0 } if ( dead_end(temp, end) == 1) { possible[worst2] = 0 } if (temp == end ) { possible[worst2] = 1 } if (s[2] == t[2] && possible[s[1]] == 1 && possible[t[1]] == 1 ) { for ( v in been ) { b[v] = "" c[v] = "" } start1 = find_next(s[1], start_pnt) went1 = s[1] l = free_path(x, start1, end, tol, b, went1) start2 = find_next(t[1], start_pnt) went2 = t[1] k = free_path(y, start2, end, tol, c, went2) delarray(b) delarray(c) delarray(x) delarray(y) if ( k < l && k >= 0) { temp = best2 best2 = worst1 worst1 = temp } } #print best1 " " possible[best1] " " best2 " " possible[best2] " " worst1 " " possible[worst1] " " worst2 " " possible[worst2] > "/dev/stderr" if(possible[best1] == 1 ) { arr[curr] = best1 } else if(possible[best2] == 1 ) { arr[curr] = best2 } else if ( possible[worst1] == 1 ) { arr[curr] = worst1 } else if ( possible[worst2] == 1) { arr[curr] = worst2 } if ( arr[curr] != "" ) { went = arr[curr] if ( arr[curr] == "up" ) { start = (start_pnt[1] + 1) ":" start_pnt[2] } if ( arr[curr] == "down" ) { start = (start_pnt[1] - 1) ":" start_pnt[2] } if ( arr[curr] == "left" ) { start = start_pnt[1] ":" (start_pnt[2] - 1) } if ( arr[curr] == "right" ) { start = start_pnt[1] ":" (start_pnt[2] + 1) } arr[curr] = start n = 1 + free_path(arr, start, end, tol, been, went, curr) delarray(been) return n } else { #print "unsuccessful free path" > "/dev/stderr" return -200 } } # FREE_PATH_ENEMY # function free_path_enemy(arr, start, end, tol, been, went, curr, temp, possible, triangulate, start_pnt, end_pnt, v, best1, best2, worst1, worst2, r, s, t, u, b, c, val, backwards, arr2, n ) { #print start ++curr been[start] arr[curr] = "" best1= ""; best2 = ""; worst1 = ""; worst2 = "" backwards = "" possible["up"] = 1 possible["down"] = 1 possible["left"] = 1 possible["right"] = 1 split(start, start_pnt, ":") split(end, end_pnt, ":") n = optimal_path(arr2, start, end, temparr, went) if ( start == end || n <= tol) { #print "successful path" > "/dev/stderr" delarray(been) return 0 } delarray(temparr) delarray(arr2) if ( went == "up" ) { backwards = "down" } if ( went == "down" ) { backwards = "up" } if ( went == "left" ) { backwards = "right" } if ( went == "right" ) { backwards = "left" } if ( backwards != "" ) { possible[backwards] = 0 } if(Illegal_Move(start_pnt[1], start_pnt[2], 2, 1) == 1) { possible["left"] = 0 } if(Illegal_Move(start_pnt[1], start_pnt[2], 3, 1) == 1) { possible["right"] = 0 } if(Illegal_Move(start_pnt[1], start_pnt[2], 1, 1) == 1) { possible["up"] = 0 } if(Illegal_Move(start_pnt[1], start_pnt[2], 4, 1) == 1) { possible["down"] = 0 } triangulate[1] = "up" ":" (end_pnt[1] - (start_pnt[1] + 1) )^2 + (end_pnt[2] - start_pnt[2])^2 triangulate[2] = "down" ":" (end_pnt[1] - (start_pnt[1] - 1) )^2 + (end_pnt[2] - start_pnt[2])^2 triangulate[3] = "right" ":" (end_pnt[1] - start_pnt[1])^2 + (end_pnt[2] - (start_pnt[2] + 1))^2 triangulate[4] = "left" ":" (end_pnt[1] - start_pnt[1])^2 + (end_pnt[2] - (start_pnt[2] - 1))^2 sort(triangulate, 4) split(triangulate[1], r, ":") best1 = r[1] split(triangulate[2], s, ":") best2 = s[1] split(triangulate[3], t, ":") worst1 = t[1] split(triangulate[4], u, ":") worst2 = u[1] #print best1 " " possible[best1] " " best2 " " possible[best2] " " worst1 " " possible[worst1] " " worst2 " " possible[worst2] temp = find_next(best1, start_pnt) if ( temp in been ) { possible[best1] = 0 } if ( dead_end_enemy(temp, end) == 1 ) { possible[best1] = 0 } if (temp == end ) { possible[best1] = 1 } split(temp, k_bomb, ":") if ( known_bomb[k_bomb[1],k_bomb[2]] == 1 ) { possible[best1] = 0 } temp = find_next(best2, start_pnt) if ( temp in been ) { possible[best2] = 0 } if ( dead_end_enemy(temp, end) == 1 ) { possible[best2] = 0 } if (temp == end ) { possible[best2] = 1 } split(temp, k_bomb, ":") if ( known_bomb[k_bomb[1],k_bomb[2]] == 1 ) { possible[best2] = 0 } temp = find_next(worst1, start_pnt) if ( temp in been ) { possible[worst1] = 0 } if ( dead_end_enemy(temp, end) == 1) { possible[worst1] = 0 } if (temp == end ) { possible[worst1] = 1 } split(temp, k_bomb, ":") if ( known_bomb[k_bomb[1],k_bomb[2]] == 1 ) { possible[worst1] = 0 } temp = find_next(worst2, start_pnt) if ( temp in been ) { possible[worst2] = 0 } if ( dead_end_enemy(temp, end) == 1) { possible[worst2] = 0 } if (temp == end ) { possible[worst2] = 1 } split(temp, k_bomb, ":") if ( known_bomb[k_bomb[1],k_bomb[2]] == 1 ) { possible[worst2] = 0 } if (s[2] == t[2] && possible[s[1]] == 1 && possible[t[1]] == 1 ) { for ( v in been ) { b[v] = "" c[v] = "" } start1 = find_next(s[1], start_pnt) went1 = s[1] l = free_path_enemy(x, start1, end, tol, b, went1) start2 = find_next(t[1], start_pnt) went2 = t[1] k = free_path_enemy(y, start2, end, tol, c, went2) delarray(b) delarray(c) delarray(x) delarray(y) if ( k < l && k >= 0) { temp = best2 best2 = worst1 worst1 = temp } } #print best1 " " possible[best1] " " best2 " " possible[best2] " " worst1 " " possible[worst1] " #" worst2 " " possible[worst2] if(possible[best1] == 1 ) { arr[curr] = best1 } else if(possible[best2] == 1 ) { arr[curr] = best2 } else if ( possible[worst1] == 1 ) { arr[curr] = worst1 } else if ( possible[worst2] == 1) { arr[curr] = worst2 } if ( arr[curr] != "" ) { went = arr[curr] if ( arr[curr] == "up" ) { start = (start_pnt[1] + 1) ":" start_pnt[2] } if ( arr[curr] == "down" ) { start = (start_pnt[1] - 1) ":" start_pnt[2] } if ( arr[curr] == "left" ) { start = start_pnt[1] ":" (start_pnt[2] - 1) } if ( arr[curr] == "right" ) { start = start_pnt[1] ":" (start_pnt[2] + 1) } arr[curr] = start n = 1 + free_path_enemy(arr, start, end, tol, been, went, curr) delarray(been) return n } else { return -200 } } #### #DEAD_END_ENEMY: helper for free_path_enemy, tells me if I'm going into a dead end or not function dead_end_enemy(potential, end, start_pnt,barriers) { split(potential, start_pnt, ":") ++barriers #for the space just came from if( Illegal_Move(start_pnt[1], start_pnt[2], 1, 1) == 1) { ++barriers } if( Illegal_Move(start_pnt[1], start_pnt[2], 2, 1) == 1) { ++barriers } if( Illegal_Move(start_pnt[1], start_pnt[2], 3, 1) == 1) { ++barriers } if( Illegal_Move(start_pnt[1], start_pnt[2], 4, 1) == 1) { ++barriers } if (barriers > 3) { return 1 } else { return 0 } } #DEAD_END: helper for free_path, tells me if I'm going into a dead end or not function dead_end(potential, end, start_pnt,barriers) { split(potential, start_pnt, ":") ++barriers #for the space just came from if( open_space(start_pnt[1], start_pnt[2], 1, 1, end) == 1) { ++barriers } if( open_space(start_pnt[1], start_pnt[2], 2, 1, end) == 1) { ++barriers } if( open_space(start_pnt[1], start_pnt[2], 3, 1, end) == 1) { ++barriers } if( open_space(start_pnt[1], start_pnt[2], 4, 1, end) == 1) { ++barriers } if (barriers > 3) { return 1 } else { return 0 } } #ECCENTRICITY: tells the eccentricity of the free path in relation to the optimal path #the higher the return value, the farther out of the way the free path is. Takes the number #of moves the optimal path returns, and the number of moves the free path returns function eccentricity(opt, free) { if (opt == 0) return 20 else return free/opt } #HIGHER_LOWER_UNKNOWN: checks to see if an enemy piece is higher, lower, or unknown function higher_lower_unknown(our_rank, enemy_index, possibilities, avg, sum, i) { for ( i = 1; i <= 9; i++) { if(enemy_possible_indx[enemy_index,i] != 0) { ++possibilities sum = sum + i } } if(enemy_possible_indx[enemy_index, B] != 0 ) { ++possibilities; sum = sum + 0 } if(enemy_possible_indx[enemy_index, "*"] != 0 ) { ++possibilities; sum = sum + 12 } if(enemy_possible_indx[enemy_index, s] != 0 ) { ++possibilities; sum = sum + 11 } #print "our rank = " our_rank "target = " enemy_location_indx[enemy_index] "sum = " sum " possiblities = " possibilities > "highlow.sav" if ( possibilities > 0 ) { avg = sum/possibilities } #print avg > "highlow.sav" if ( possibilities >= 5) { return 0 } else if ( possibilities == 1 && avg > our_rank ) { return 2 } else if ( possibilities == 1 && avg <= our_rank ) { return -2 } else if ( avg > our_rank ) { return 1 } else if ( avg <= our_rank ) { return -1 } } #MOVE_SCOUT: returns a weight of 0...100, for moving a scout. Takes into account how #many moves since it was last moved, whether there are any unknown pieces in the front, #and whether it is critical to find out a rank, such as in a defensive situation. #STATUS: done. function move_scout( l,max_weight, weight, i, j, a, b) { print "Move Scout" > "/dev/stderr" #print "max prob of flag = " max_probability_of_flag > "/dev/stderr" l = scan_the_front(enemies) #find the best enemy to scout for ( j = 1; j <= l; j++ ) { #print "scouting " enemies[j] > "/dev/stderr" #print higher_lower_unknown(9, enemies[j]) >> "/dev/stderr" if ( higher_lower_unknown(9, enemies[j]) == 0 ) { weight = 35 #if unknown enemy is near our flag if( dist_to_our_flag(enemy_location_indx[enemies[j]]) < 4 ) { weight = weight + 35 } #if unknown enemy is near their flag if( dist_to_their_flag(enemy_location_indx[enemies[j]]) <= 4){ weight = weight + 15 } if ( weight > max_weight ) { scout_enemy_index = enemies[j] max_weight = weight } } } #print "weight = " weight > "/dev/stderr" #print "scout_enemy_index = " enemy_location_indx[scout_enemy_index] > "/dev/stderr" #print "find the best scout for the job" > "/dev/stderr" min_ecc = 10 if ( weight != 0 ) { for ( i = 0; i <= 39; i++ ) { #print our_rank_indx[i] " " i if ( our_rank_indx[i] == 9 && our_location_indx[i] != "-1:-1" ) { print "in part 1" >> "slog.sav" opt = optimal_path(scout_moves_temp, our_location_indx[i], enemy_location_indx[scout_enemy_index]) delarray(scout_moves_temp) #print our_location_indx[i] " " enemy_location_indx[scout_enemy_index] > "/dev/stderr" free = free_path(scout_moves_temp, our_location_indx[i], enemy_location_indx[scout_enemy_index], 0) e = eccentricity(opt, free) if ( e < min_ecc && e > 0 ) { delarray(scout_moves) for ( z = 1; z <= free; z++ ) { scout_moves[z] = scout_moves_temp[z] } #print "in" > "/dev/stderr" dir = find_dir(our_location_indx[i], scout_moves[1]) scout_index = i min_ecc = e } } } #if the best path is a sucky path, reduce the weight if ( min_ecc > 2 ) { max_weight = max_weight - 20 } max_weight = max_weight + scout_last_move * 10 if (max_weight > 100 ) { max_weight = 100 } delarray(scout_moves_temp) #find out how many moves scout can go if ( dir == "" ) { print "in part 2" >> "slog.sav" for ( i = 0; i <= 39; i++) { if ( our_rank_indx[i] == 9 && our_location_indx[i] != "-1:-1" ) { for ( j = 1; j <= l; j++ ) { #print enemies[j] " " our_location_indx[i] " " enemy_location_indx[enemies[j]] >> "/dev/stderr" m = free_path(scout_moves_temp, our_location_indx[i], enemy_location_indx[enemies[j]],0) #print "past free_path" >> "/dev/stderr" if (m > 0 ) { break } else { delarray(scout_moves_temp) } } if ( m > 0 ) { print "in part 3, m = " m >> "slog.sav" dir = find_dir(our_location_indx[i], scout_moves_temp[1]) scout_index = i n = scout_can_move(scout_moves_temp, dir) delarray(enemies) delarray(scout_moves_temp) return 20 ":" n ":" dir } } } } else { n = scout_can_move(scout_moves, dir) delarray(enemies) max_weight = max_weight + 1 return max_weight ":" n ":" dir } } return "0:0:0" } #SCAN_THE_FRONT: scans the front most enemy piece in each col., and stores its index in "array", #helper for move_scout function scan_the_front(scan, i, j, k) { #print "Scan the Front" > "/dev/stderr" for ( i = 1; i <= 10; i++ ) { for ( j = 1; j <= 10; j++) { if ( (j,i) in enemy_row_col ) { if ( enemy_row_col[j,i] != "" && enemy_row_col[j,i] != "-1") { ++k #print i "," j > "/dev/stderr" scan[k] = enemy_row_col[j,i] break } } } } return k } #SCOUT_CAN_MOVE: returns how many moves a scout can move from a path array function scout_can_move(array, initial) { #print "Scout can move" > "/dev/stderr" #print "initial = " initial > "/dev/stderr" for ( var in array ) { print array[var] >> "slog.sav" } i = 0 next_move = initial while ( next_move == initial ) { i++ #print array[i] " " array[i + 1] > "/dev/stderr" next_move = find_dir(array[i], array[i + 1]) } #print "done " i-1 > "/dev/stderr" return i } #FIND_DIR: takes two points returns direction function find_dir(start, end) { #print "find_dir " start " " end > "/dev/stderr" split(start, start_, ":") split(end, end_, ":") if( start_[1] - end_[1] == 1 ) { return "down" } if( start_[1] - end_[1] == -1) { return "up" } if( start_[2] - end_[2] == 1) { return "left" } if( start_[2] - end_[2] == -1) { return "right" } } #DELARRY: deletes all elements in array "a" function delarray(a, i) { for ( i in a ) { delete a[i] } } #Illegal_Move function Illegal_Move(row, col, direction, num_spaces, new_col, new_row, x, new_row_col, bad_move) # takes as arguments (row, col, direction, num_spaces) { #direction 1(up), 2(left), 3 (right), 4(down) bad_move = 0 if (direction == 2) { new_col = col - num_spaces new_row = row } if (direction == 3) { new_col = col + num_spaces new_row = row } if (direction == 1) { new_row = row + num_spaces new_col = col } if (direction == 4) { new_row = row - num_spaces new_col = col } if (new_row > 10 || new_row < 1 || new_col > 10 || new_col < 1) { #print "Off of board" bad_move = 1 } if ( (new_row == 5 || new_row == 6) && (new_col == 3 || new_col == 4 || new_col == 7 || new_col == 8) ) { #print "In hazard" bad_move = 1 } # check if attacking friendly # new_row_col = new_row ":" new_col for (x = 0; x <= 39; x++) { if (new_row_col == our_location_indx[x]) bad_move = 1 } if (bad_move == 1) return 1 else return 0 } #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #Init_Game() function Init_Game() # this function takes no parameters at input { print "Init_Game" > "/dev/stderr" # Do things that we only are going to do once per game (ie set up our and # enemy indices, init brute squads, etc...) getline < "first_move.sav" first_move = $1 close("first_move.sav") if (first_move == 1) { print "***************DOING THE INIT**********" > "/dev/stderr" # Init_Flag_Probs() Init_Location_Indx() Init_BS_Members() print "2" > "first_move.sav" close("first_move.sav") } } #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #Init_Location_Indx function Init_Location_Indx(row, col, en_idx, our_idx, enemy_index, rnk_idx, rank_cnt, enemy_idx, r, c) # this function takes no input parameters { #----------------------------------------------- #Init enemy_location_indx[] and enemy_row_col[] # enemy_idx = 0 # init enemy_location_indx # for (row = 7; row <= 10; row++) for (col = 1; col <= 10; col++) { enemy_location_indx[enemy_idx] = row":"col enemy_row_col[row, col] = enemy_idx enemy_idx++ } # #----------------------------------------------- # ----------------------------------------------- # Init our_location_indx[] # our_idx = 0 for(row = 1; row <= 4; row++) for(col = 1; col <= 10; col++) { our_location_indx[our_idx] = row":"col our_idx++ } # # ---------------------------------------------- # ---------------------------------------------- # Init enemy_possible_indx # for(enemy_index = 0; enemy_index <= 39; enemy_index++) { for (rank_cnt = 1; rank_cnt <= 9; rank_cnt++) enemy_possible_indx[enemy_index, rank_cnt] = "1" enemy_possible_indx[enemy_index, "s"] = "1" enemy_possible_indx[enemy_index, "*"] = "1" enemy_possible_indx[enemy_index, "B"] = "1" } # # ---------------------------------------------- # ---------------------------------------------- # Read the file our.formation in order to set up # our_rank_indx[]. for ( j = 1; j <=6; j++ ) { getline < "board" } rnk_idx = 39 for(r = 0; r < 4; r++) { getline board_row < "board" for (c = 10; c >= 1; c--) { result = substr(board_row, c, 1) if (result == "*" ) { flag_indx = rnk_idx; print "flag_indx = " flag_indx > "/dev/stderr" } our_rank_indx[rnk_idx] = result rnk_idx-- } } close("board") # # ---------------------------------------------- } #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #Move_Miner function Move_Miner(miner_value, miner_index, miner_move) { print "Move Miner" > "/dev/stderr" # going to return a value between 0.. # # bottom left corner is (r,c) (1,1) or index = 0 #--------------------------------------------------------------------------------------------- # mv_idx = 0 for (q = 0; q <= 39; q++) { if (our_rank_indx[q] == "8" && our_location_indx[q] != "-1:-1" && max_probability_of_bomb != "" ) { m_num_moves[1] = free_path(miner_array_1, our_location_indx[q], max_probability_of_bomb, 0) if ( second_max_probability_of_bomb != "" ) { m_num_moves[2] = free_path(miner_array_2, our_location_indx[q], second_max_probability_of_bomb, 0) } else { m_num_moves[2] = 0 } } #print "after free_paths" if( m_num_moves[1] > 0 || m_num_moves[2] > 0 ) { print "there is a good free path to a bomb" > "mlog.sav" print "num_moves[1] = " m_num_moves[1] > "mlog.sav" print "num_moves[2] = " m_num_moves[2] > "mlog.sav" smallest_num_moves = 35 smallest_idx = 0 for (nm_idx in m_num_moves) { if(m_num_moves[nm_idx] < smallest_num_moves && m_num_moves[nm_idx] > 0) { print "not too many moves too!" > "mlog.sav" smallest_num_moves = m_num_moves[nm_idx] smallest_idx = nm_idx } } print "smallest_idx = " smallest_idx >> "mlog.sav" print "mv_idx = " mv_idx > "mlog.sav" print "location: " our_location_indx[q] >> "mlog.sav" mmove_weight[mv_idx] = 100 - (smallest_idx * 15) print "mmove_weight[mv_idx] = " mmove_weight[mv_idx] >> "mlog.sav" mmove_num_moves[mv_idx] = m_num_moves[smallest_idx] print "mmove_num_moves[mv_idx] = " mmove_num_moves[mv_idx] >> "mlog.sav" mmove_idx[mv_idx] = q if (smallest_idx == 1) mmove_next_move[mv_idx] = miner_array_1[1] if (smallest_idx == 2) mmove_next_move[mv_idx] = miner_array_2[1] print "mmove_next_move[mv_idx] = " mmove_next_move[mv_idx] >> "mlog.sav" mv_idx++ } m_num_moves[1] = 0 m_num_moves[2] = 0 } # end for(q) # #--------------------------------------------------------------------------------------------- #================================================================================ # search the best move # for (bst_idx = 0; bst_idx < mv_idx; bst_idx++) { best_move = -10 best_move_idx = -10 if ( ( (mmove_weight[bst_idx] - mmove_num_moves[bst_idx]) > best_move) ) { #print "found better move" > "/dev/stderr" best_move = mmove_weight[bst_idx] - mmove_num_moves[bst_idx] best_move_idx = bst_idx } } # #================================================================================ print "best_move_idx = " best_move_idx >> "mlog.sav" miner_value[1] = best_move print "miner value = " miner_value[1] >> "mlog.sav" miner_index[1] = mmove_idx[best_move_idx] miner_move[1] = mmove_next_move[best_move_idx] close("mlog.sav") } # the end #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ##Move_BS_Member function Move_BS_Member(bs_move_weight, bs_next_move, bs_idx, found_a_move, y ) { print "Move_BS_Member" > "/dev/stderr" #print "Max Prob of Flag" > "/dev/stderr" #print max_probability_of_flag > "/dev/stderr" # going to scan through all members of the brute squad and give each a weight # from spaces away from flag + move_moves_us_closer_to_flag + last_time_piece_moved + # enemy piece in way is higher_lower_unknown found_a_move = -10 for (idx = 0; idx <= 39; idx++) { if (in_a_bs[idx] == 1 && our_location_indx[idx] != "-1:-1" && !(our_rank_indx[idx] == "B") && !(our_rank_indx[idx] == "*") && our_rank_indx[idx] <= 6 ) { # check if the piece can make it to the flag within a tolerance of 0..2 for (tol = 0; tol <= 2; tol++) { if ( tol != 1 ) { if ((free_rtn = free_path_enemy(bs_mv_arr, our_location_indx[idx], max_probability_of_flag, tol)) > 0) { found_a_move = 10 the_tol = tol break } } } bs_move_tol[idx] = the_tol bs_move_wt[idx] = (32 - (tol * 15)) bs_move_mv[idx] = bs_mv_arr[1] #----------------------------------------------------------- # check if an enemy piece is is the space we want to move to reduce bs_move_wt if it # is unknown piece or if it can kill us and add weight if we can kill it # split(bs_mv_arr[1], our_mv_r_c, ":") enemy_idx = find_index(our_mv_r_c[1], our_mv_r_c[2], enemy_location_indx) if (enemy_idx != -1) { # there is an enemy piece in the space we want to move to prob_en_rank = higher_lower_unknown(our_rank_indx[idx], enemy_idx) print "probable rank is " prob_en_rank > "/dev/stderr" if (prob_en_rank == 2) # definately lower bs_move_wt[idx] = bs_move_wt[idx] + 90 if (prob_en_rank == -1) # enemy prob more powerful bs_move_wt[idx] = bs_move_wt[idx] - 20 if (prob_en_rank == 1) # enemy prob less powerful bs_move_wt[idx] = bs_move_wt[idx] + 30 if (prob_en_rank == -2) # enemy definately higher bs_move_wt[idx] = bs_move_wt[idx] - 100 if (prb_en_rank == 0 ) bs_move_wt[idx] = bs_move_wt[idx] + 15 } # #----------------------------------------------------------- #=========================================================== # dst_to_flag = dist_to_their_flag(our_location_indx[idx]) if (dst_to_flag < 2 && dst_to_flag > 0) bs_move_wt[idx] = bs_move_wt[idx] + 50 if (dst_to_flag < 4 && dst_to_flag >= 2) bs_move_wt[idx] = bs_move_wt[idx] + 25 if (dst_to_flag < 6 && dst_to_flag >= 4) bs_move_wt[idx] = bs_move_wt[idx] + 10 if (dst_to_flag < 8 && dst_to_flag >=6) bs_move_wt[idx] = bs_move_wt[idx] + 5 # #=========================================================== } } # end for(idx) if (found_a_move > 1) { # seach for the best move and assign those values to the prototype parameters # highest_weight = -100 for (srch_idx = 0; srch_idx <= 39; srch_idx++) { if (bs_move_wt[srch_idx] > highest_weight) { highest_weight = bs_move_wt[srch_idx] h_idx = srch_idx } } #print "Highest BS weight" > "/dev/stderr" #print highest_weight > "/dev/stderr" #print "****BS MOVE***" > "/dev/stderr" #print bs_move_mv[h_idx] > "/dev/stderr" bs_move_weight[1] = highest_weight bs_next_move[1] = bs_move_mv[h_idx] bs_idx[1] = h_idx } else { #print "NO BS MOVE" > "/dev/stderr" print "NO BS MOVE" >> "log.sav" bs_move_weight[1] = 0 bs_next_move[1] = "0:0" bs_idx[1] = -1 } } # the end #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ##Calc_Max_Prob_Of_Flag function Calc_Max_Prob_Of_Flag(r,c, highest_prob) # this functions takes no parameters { #print "Calc_Max_Prob_Of_Flag" > "/dev/stderr" highest_prob = -1 for (r = 1; r <=10; r++) { for (c = 1; c <= 10; c++) { if( not_a_flag_bomb[r,c] == 1 ) { probability_of_flag[r,c] = -1 } if (probability_of_flag[r, c] > highest_prob) { highest_prob = probability_of_flag[r, c] highest_row = r highest_col = c } } } max_probability_of_flag = highest_row":"highest_col print " " >> "/dev/stderr" print "MAX PROB FLAG: " max_probability_of_flag >> "/dev/stderr" # return max_probability_of_flag } #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # RESTORE_INFO # # a typical call would be Restore_Info(0, the_kim, "kimster.txt") where the_kim is an array function Restore_Info(which_one, array_sav, file_sav, r, c, idx, r_idx) # which_one: 1 two-dim array # while_one: 2 one-dim array # which_one: 3 enemy_possible_indx # which_one: 4 misc data { #------------------------------------------------------- # #print "Restore_Info" > "/dev/stderr" if (which_one == 1) { # get us past the file name we put on top of file getline < file_sav for (r=1; r <= 10; r++) for (c=1; c <= 10; c++) getline array_sav[r, c] < file_sav close(file_sav) } if (which_one == 2) { idx = 0 getline < file_sav # get us past the name we put on top of file while(array_sav[idx - 1] != "-999") { getline array_sav[idx] < file_sav idx++ } close(file_sav) for (cnt in array_sav) if (array_sav[cnt] == "-999") delete array_sav[cnt] } #--------------------------------------------------- # this is for restoring "enemy_poss_indx.sav" if (which_one == 3) { # clear the title off getline < "enemy_poss_indx.sav" for (idx = 0; idx <= 39; idx++) { for ( r_idx = 1; r_idx <= 9; r_idx++) getline enemy_possible_indx[idx, r_idx] < "enemy_poss_indx.sav" getline enemy_possible_indx[idx, "s"] < "enemy_poss_indx.sav" getline enemy_possible_indx[idx, "*"] < "enemy_poss_indx.sav" getline enemy_possible_indx[idx, "B"] < "enemy_poss_indx.sav" } } #--------------------------------------------------- if (which_one == 4) { getline < "other_data.sav" getline < "other_data.sav" getline scout_last_move < "other_data.sav" getline < "other_data.sav" getline miner_last_move < "other_data.sav" getline < "other_data.sav" getline bs_last_move < "other_data.sav" getline flag_indx < "other_data.sav" getline max_probability_of_flag < "other_data.sav" getline max_probability_of_bomb < "other_data.sav" getline second_max_probability_of_bomb < "other_data.sav" close("other_data.sav") } } #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # CALL_RESTORE_INFO # function Call_Restore_Info() { print "Call_Restore_Info" > "/dev/stderr" Restore_Info(1, probability_of_flag, "prob_of_flag.sav") Restore_Info(2, our_rank_indx, "our_rank_indx.sav") Restore_Info(2, our_location_indx, "our_loc_indx.sav") Restore_Info(2, in_a_bs, "in_a_bs.sav") Restore_Info(2, enemy_location_indx, "enemy_loc_indx.sav") Restore_Info(1, not_a_flag_bomb, "not_flag_bomb.sav") Restore_Info(1, known_bomb, "known_bomb.sav" ) Restore_Info(1, probability_of_flag, "prob_of_flag.sav") Restore_Info(1, probability_of_bomb, "prob_of_bomb.sav") # enemy possible index Restore_Info(3) Restore_Info(1, enemy_row_col, "enemy_row_col.sav") Restore_Info(4) } #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ##Update_Our_Locations function Update_Our_Locations(x) # this function takes no parameters { for(x = 0; x <= 39; x++) { if (our_location_indx[x] == my_row1":"my_col1) { our_location_indx[x] = my_row2":"my_col2 break } } } #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ function Update_His_Locations(enemy_index) { enemy_index = enemy_row_col[his_row1, his_col1] enemy_row_col[his_row1, his_col1] = -1 # updated enemy_location_indx[enemy_index] = his_row2":"his_col2 # updated enemy_row_col[his_row2, his_col2] = enemy_index } #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ##How_Well_We_Are_Doing function How_Well_We_Are_Doing(my_remain_score, his_remain_score, his_remain_score2) # this function takes no parameters { #print "How Well_We_Are_Doing" > "/dev/stderr" my_remain_score = my_remain["1"] * 12 + my_remain["2"] * 9 + my_remain["3"] * 7 + my_remain["4"] * 6 + my_remain["5"] * 5 + my_remain["6"] * 4 + my_remain["7"] * 3 + my_remain["8"] * 4 + my_remain["9"] * 6 + my_remain["B"] * 5 + my_remain["s"] * 10 his_remain_score = his_remain["1"] * 12 + his_remain["2"] * 9 + his_remain["3"] * 7 + his_remain["4"] * 6 + his_remain["5"] * 5 his_remain_score2 = his_remain["6"] * 4 + his_remain["7"] * 3 + his_remain["8"] * 4 + his_remain["9"] * 6 + his_remain["B"] * 5 + his_remain["s"] * 10 his_remain_score = his_remain_score + his_remain_score2 if (my_remain["B"] == 0) my_remain_score = my_remain_score - 5 if (his_remain["B"] == 0) his_remain_score = his_remain_score - 5 how_are_we_doing = my_remain_score - his_remain_score + max_probability_of_flag # print "how_are_we_doing: " # print how_are_we_doing return how_are_we_doing } #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ##Revealed_Our_Piece function Revealed_Our_Piece(enm_index, enemy_indx, x) # this function takes no arguments { #print "Revealed_Our_Piece" > "/dev/stderr" #------------------------ our move ---------------------------- # we killed them if (my_move_action == "capture") { his_remain[my_move_his_piece]-- enm_index = enemy_row_col[my_row2, my_col2] enemy_row_col[my_row2, my_col2] = -1 for (x=0; x<=39; x++) { if(enemy_location_indx[x] == my_row2":"my_col2) enemy_location_indx[x] = "-1:-1" } } # we both died **TESTED** if (my_move_action == "equal-ranks") { his_remain[my_move_his_piece]-- enm_index = enemy_row_col[my_row2, my_col2] enemy_row_col[my_row2, my_col2] = -1 for (x=0; x<=39; x++) { if(enemy_location_indx[x] == my_row2":"my_col2) enemy_location_indx[x] = "-1:-1" } my_remain[my_move_my_piece]-- for (x=0; x <= 39; x++) { if (our_location_indx[x] == my_row2":"my_col2) our_location_indx[x] = "-1:-1" } } # they killed us if (my_move_action == "defender-survives") { my_remain[my_move_my_piece]-- for (x=0; x <= 39; x++) { if (our_location_indx[x] == my_row2":"my_col2) our_location_indx[x] = "-1:-1" } # update info on his possible rank enemy_indx = enemy_row_col[my_row2, my_col2] #clear all the possibles from the enemy # for(x = 1; x <= 9; x++) enemy_possible_indx[enemy_indx, x] = 0 enemy_possible_indx[enemy_indx, "s"] = 0 enemy_possible_indx[enemy_indx, "*"] = 0 enemy_possible_indx[enemy_indx, "B"] = 0 # # then just set the one rank we just found out about # enemy_possible_indx[enemy_indx, my_move_his_piece] = 1 } if (my_move_action == "bomb-is-fatal") { my_remain[my_move_my_piece]-- for (x=0; x <= 39; x++) { #NOTE: even though our piece really isn't at # my_row2:my_col2 (since it got killed) # the pdateLocation() says it is there if (our_location_indx[x] == my_row2":"my_col2) our_location_indx[x] = "-1:-1" } enemy_indx = enemy_row_col[my_row2, my_col2] for(x = 1; x <= 9; x++) enemy_possible_indx[enemy_indx, x] = 0 enemy_possible_indx[enemy_indx, "s"] = 0 enemy_possible_indx[enemy_indx, "*"] = 0 enemy_possible_indx[enemy_indx, "B"] = 0 enemy_possible_indx[enemy_indx, "B"] = 1 } if (my_move_action == "miner-defuses-bomb") { his_remain["B"]-- enm_index = enemy_row_col[my_row2, my_col2] enemy_row_col[my_row2, my_col2] = -1 enemy_location_indx[enm_index] = "-1:-1" not_a_flag_bomb[my_row2, my_col2] = 1 known_bomb[my_row2, my_col2] = 0 probability_of_bomb[my_row2, my_col2] = -1 } if (my_move_action == "spy-kills-marshall") { his_remain["1"]-- enm_index = enemy_row_col[my_row2, my_col2] enemy_row_col[my_row2, my_col2] = -1 for (x=0; x<=39; x++) { if(enemy_location_indx[x] == my_row2":"my_col2) enemy_location_indx[x] = "-1:-1" } } } #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ function Revealed_Enemy_Piece(enm_index, enemy_indx, x) { # ------------------------ Their Move ------------------------------ # they killed us if (his_move_action == "capture") { my_remain[his_move_my_piece]-- for (x=0; x <= 39; x++) { if (our_location_indx[x] == his_row2":"his_col2) our_location_indx[x] = "-1:-1" } enemy_indx = enemy_row_col[his_row2, his_col2] for(x = 1; x <= 9; x++) enemy_possible_indx[enemy_indx, x] = 0 enemy_possible_indx[enemy_indx, "s"] = 0 enemy_possible_indx[enemy_indx, "*"] = 0 enemy_possible_indx[enemy_indx, "B"] = 0 enemy_possible_indx[enemy_indx, his_move_his_piece] = 1 } # we both died if (his_move_action == "equal-ranks") { my_remain[his_move_my_piece]-- for (x=0; x <= 39; x++) { if (our_location_indx[x] == his_row2":"his_col2) our_location_indx[x] = "-1:-1" } his_remain[his_move_his_piece]-- enm_index = enemy_row_col[his_row2, his_col2] enemy_row_col[his_row2, his_col2] = -1 for (x=0; x<=39; x++) { if(enemy_location_indx[x] == his_row2":"his_col2) enemy_location_indx[x] = "-1:-1" } } # we killed them if (his_move_action == "defender-survives") { his_remain[his_move_his_piece]-- enm_index = enemy_row_col[his_row2, his_col2] enemy_row_col[his_row2, his_col2] = -1 for (x=0; x<=39; x++) { if(enemy_location_indx[x] == his_row2":"his_col2) enemy_location_indx[x] = "-1:-1" } } # he got our bomb if (his_move_action == "miner-defuses-bomb") { my_remain["B"]-- for (x=0; x <= 39; x++) { if (our_location_indx[x] == his_row2":"his_col2) our_location_indx[x] = "-1:-1" } } # our bomb got him if (his_move_action == "bomb-is-fatal") { his_remain[his_move_his_piece]-- enm_index = enemy_row_col[his_row2, his_col2] enemy_row_col[his_row2, his_col2] = -1 for (x=0; x<=39; x++) { if(enemy_location_indx[x] == his_row2":"his_col2) enemy_location_indx[x] = "-1:-1" } } # his spy killed our marshall?? if (his_move_action == "spy-kills-marshall") { my_remain["1"]-- for (x=0; x <= 39; x++) { if (our_location_indx[x] == his_row2":"his_col2) our_location_indx[x] = "-1:-1" } enemy_indx = enemy_row_col[his_row2, his_col2] for(x = 1; x <= 9; x++) enemy_possible_indx[enemy_indx, x] = 0 enemy_possible_indx[enemy_indx, "*"] = 0 enemy_possible_indx[enemy_indx, "B"] = 0 enemy_possible_indx[enemy_indx, "s"] = 1 } #------------------------------------------------------------------------- # if we discover that the enemy piece that just died was the last one # of its rank, we then clear the chance of any other enemy piece # being that rank if (his_move_action == "defender-survives" || his_move_action == "equal-ranks" ) if (his_remain[his_move_his_piece] == 0) { for(x = 0; x <= 39; x++) { enemy_possible_indx[x, his_move_his_piece] = 0 } } if (my_move_action == "capture" || my_move_action == "equal-ranks") if (his_remain[my_move_his_piece] == 0) { for(x = 0; x <= 39; x++) { enemy_possible_indx[x, my_move_his_piece] = 0 } } print " " >> "the_result.sav" print " " >> "the_result.sav" print "OUR LOCATIONS" >> "the_result.sav" for (x=0; x<=39; x++) print our_location_indx[x] >> "the_result.sav" print " " >> "the_result.sav" print " " >> "the_result.sav" print " HIS LOCATIONS" >> "the_result.sav" for (x=0; x<=39; x++) print enemy_location_indx[x] >> "the_result.sav" close("the_result.sav") } #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ##Save_Info function Save_Info(r, c, idx) # this function takes no input parameters # saves probability_of_flag in prob_of_flag.sav # our_rank_indx in our_rank_indx.sav # our_location_indx in our_loc_indx.sav # in_a_bs in in_a_bs.sav # enemy_location_indx enemy_loc_indx.sav # not_a_flag_bomb in not_flag_bomb.sav # probability_of_flag in prob_of_flag.sav # probability_of_bomb in prob_of_bomb.sav # enemy_possible_indx in enemy_poss_indx.sav # enemy_row_col in enemy_row_col.sav { print "Save_Info" > "/dev/stderr" #+++++++++++++++++++++++++++++++++++++++++++++++++++ #**works print "probability_of_flag" > "prob_of_flag.sav" for (r = 1; r <= 10; r++) for (c = 1; c <= 10; c++) print probability_of_flag[r, c] >> "prob_of_flag.sav" print "-999" >> "prob_of_flag.sav" close("prob_of_flag.sav") #+++++++++++++++++++++++++++++++++++++++++++++++++++ #++++++++++++++++++++++++++++++++++++ #** works print "our_rank_indx" > "our_rank_indx.sav" for (idx = 0; idx <= 39; idx++) print our_rank_indx[idx] >> "our_rank_indx.sav" print "-999" >> "our_rank_indx.sav" close("our_rank_indx.sav") #++++++++++++++++++++++++++++++++++++ #+++++++++++++++++++++++++++++++++++++++++++++++++++++ # ** works print "our_location_indx" > "our_loc_indx.sav" for (idx = 0; idx <= 39; idx++) print our_location_indx[idx] >> "our_loc_indx.sav" print "-999" >> "our_loc_indx.sav" close("our_loc_indx.sav") #+++++++++++++++++++++++++++++++++++++++++++++++++++++ #+++++++++++++++++++++++++++++++++++ # **works print "in_a_bs" > "in_a_bs.sav" for(idx = 0; idx <= 39; idx++) print in_a_bs[idx] >> "in_a_bs.sav" print "-999" >> "in_a_bs.sav" close("in_a_bs.sav") #++++++++++++++++++++++++++++++++++++ #+++++++++++++++++++++++++++++++++++++++++++++++++++++ print "enemy_location_indx" > "enemy_loc_indx.sav" for (idx = 0; idx <= 39; idx++) print enemy_location_indx[idx] >> "enemy_loc_indx.sav" print "-999" >> "enemy_loc_indx.sav" close("enemy_loc_indx.sav") #+++++++++++++++++++++++++++++++++++++++++++++++++++++ #++++++++++++++++++++++++++++++++++ # *** works print "not_flag_bomb" > "not_flag_bomb.sav" for (r = 1; r <= 10; r++) for (c = 1; c <= 10; c++) print not_a_flag_bomb[r, c] >> "not_flag_bomb.sav" print "-999" >> "not_flag_bomb.sav" close("not_flag_bomb.sav") #++++++++++++++++++++++++++++++++++ #++++++++++++++++++++++++++++++++++ # *** works print "known_bomb" > "known_bomb.sav" for (r = 1; r <= 10; r++) for (c = 1; c <= 10; c++) print known_bomb[r, c] >> "known_bomb.sav" print "-999" >> "known_bomb.sav" close("known_bomb.sav") #++++++++++++++++++++++++++++++++++ #++++++++++++++++++++++++++++++++++++++++++++++++++++++ # *** works print "prob_of_flag" > "prob_of_flag.sav" for (r = 1; r <= 10; r++) for (c = 1; c <= 10; c++) print probability_of_flag[r, c] >> "prob_of_flag.sav" print "-999" >> "prob_of_flag.sav" close("prob_of_flag.sav") #++++++++++++++++++++++++++++++++++++++++++++++++++++++ #+++++++++++++++++++++++++++++++++++ # ***works print "prob_of_bomb" > "prob_of_bomb.sav" for (r = 1; r <= 10; r++) for (c = 1; c <= 10; c++) print probability_of_bomb[r, c] >> "prob_of_bomb.sav" print "-999" >> "prob_of_bomb.sav" close("prob_of_bomb.sav") #+++++++++++++++++++++++++++++++++++ #++++++++++++++++++++++++++++++++++++++ print "enemy_possible_indx" > "enemy_poss_indx.sav" for (idx = 0; idx <= 39; idx++) { for ( r_idx = 1; r_idx <=9; r_idx++) { #print enemy_possible_indx[idx, r_idx] print enemy_possible_indx[idx, r_idx] >> "enemy_poss_indx.sav" } print enemy_possible_indx[idx, "s"] >> "enemy_poss_indx.sav" print enemy_possible_indx[idx, "*"] >> "enemy_poss_indx.sav" print enemy_possible_indx[idx, "B"] >> "enemy_poss_indx.sav" } print "-999" >> "enemy_poss_indx.sav" close("enemy_poss_indx.sav") #++++++++++++++++++++++++++++++++++++++ #+++++++++++++++++++++++++++++++++++++++++++++++++++++++ #works print "enemy_row_col" > "enemy_row_col.sav" for (r = 1; r <=10; r++) for (c = 1; c <= 10; c++) print enemy_row_col[r, c] >> "enemy_row_col.sav" print "-999" >> "enemy_row_col.sav" close("enemy_row_col.sav") #+++++++++++++++++++++++++++++++++++++++++++++++++++++++ # other things to save print "misc. saved data" > "other_data.sav" #1 print "scout_last_move" >> "other_data.sav" #2 print scout_last_move >> "other_data.sav" #3 print "miner_last_move" >> "other_data.sav" #4 print miner_last_move >> "other_data.sav" #5 print "bs_last_move" >> "other_data.sav" #6 print bs_last_move >> "other_data.sav" #7 print flag_indx >> "other_data.sav" #8 print max_probability_of_flag >> "other_data.sav" #9 print max_probability_of_bomb >> "other_data.sav" #10 print second_max_probability_of_bomb >> "other_data.sav" #11 close("other_data.sav") } #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ##Init_BS_Members function Init_BS_Members(mem_idx) { print "Init_BS_Members" >> "/dev/stderr" for (mem_idx = 0; mem_idx <= 39; mem_idx++) in_a_bs[mem_idx] = 1 } #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ##Recent_Results function Recent_Results() { print "Recent_Results" > "/dev/stderr" # this function will read record_tail (which is his last result) # along with record_penultimate (which is my last result) # ################################################ getline my_last_result < "recordpenultimate" getline my_last_move < "recordpenultimate" close("recordpenultimate") print " " >> "the_result.sav" print "my_result" >> "the_result.sav" print my_last_result >> "the_result.sav" print my_last_move >> "the_result.sav" split(my_last_result,mylastres," ") my_move_action = mylastres[1] my_move_my_piece = mylastres[2] my_move_his_piece = mylastres[3] split(my_last_move, my_last_mv," ") my_row1 = my_last_mv[1] my_col1 = my_last_mv[2] my_row2 = my_last_mv[3] my_col2 = my_last_mv[4] # ---------------------------------------------- getline his_last_result < "recordtail" getline his_last_move < "recordtail" close("recordtail") print "his result" >> "the_result.sav" print his_last_result >> "the_result.sav" print his_last_move >> "the_result.sav" print " " >> "the_result.sav" close("the_result.sav") split(his_last_result,hislastres," ") his_move_action = hislastres[1] his_move_his_piece = hislastres[2] his_move_my_piece = hislastres[3] split(his_last_move, his_last_mv," ") his_row1 = his_last_mv[1] his_col1 = his_last_mv[2] his_row2 = his_last_mv[3] his_col2 = his_last_mv[4] # ---------------------------------------------- } #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ##calc_new_row_col function calc_new_row_col(old_row, old_col, direction, num_moves) { print "calc_new_row_col" > "/dev/stderr" if (direction == "up" ) { new_r_c_a[1] = old_row + num_moves new_r_c_a[2] = old_col } if (direction == "down" ) { new_r_c_a[1] = old_row - num_moves new_r_c_a[2] = old_col } if (direction == "left" ) { new_r_c_a[1] = old_row new_r_c_a[2] = old_col - num_moves } if (direction == "right" ) { new_r_c_a[1] = old_row new_r_c_a[2] = old_col + num_moves } } #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ##Choose_Move function Choose_Move(mv_from, mv_to) # this functions doesn't take any parameters as input # it RETURNS mv_from and mv_to { print "Choose_Move" > "/dev/stderr" How_Well_We_Are_Doing() Move_Miner(m_value, miner_index, miner_move) Move_BS_Member(b_value, bs_move, bs_index) def_value = defensive_move() # the to and from are held in defense_our_piece and defense_enemy_piece # scout_rtn is weight:num_moves:direction; "scout_index" indicates which scout is to move # scout_rtn = move_scout() print "scout returns = " scout_rtn >> "slog.sav" split(scout_rtn, scout_vals,":") scout_value = scout_vals[1] #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ split(bs_move[1], bs_stuff,":") split(our_location_indx[defense_our_piece], def_stuf_a, ":") split(defense_move_to, def_stuf_b, ":") if ((scout_vals[1] == 0 || scout_vals[1] == 0 || scout_vals[1] == 0 || scout_vals[1] == 0) && (bs_stuff[1] == 0 || bs_stuff[2] == 0) && (def_stuf_a[1] == 0 || def_stuf_a[2] == 0 || def_stuf_b[1] == 0 || def_stuf_b[2] == 0)) { print " " >> "log.sav" print "Random Move since there wasn't any good moves" >> "log.sav" Random_Move() return 0 } #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #========================================================================================== # print miner_last_move " " scout_last_move " " bs_last_move > "/dev/stderr" if ( b_value[1] == 0 ) { b_value[1] = -500 } b_value[1] = b_value[1] + bs_last_move * 5 if (how_well_we_are_doing <= -20) def_value = def_value * 1.7 if (how_well_we_are_doing <= -10 && how_well_we_are_doing > -20 ) def_value = def_value * 1.5 if (how_well_we_are_doing <= -9 && how_well_we_are_doing > -10 ) def_value = def_value * 1.2 if (how_well_we_are_doing > 10 && how_well_we_are_doing < 20) def_value = def_value * 1.1 # #========================================================================================== print " " >> "log.sav" print ("miner: " m_value[1]) (" bs: " b_value[1]) (" scout " scout_value) (" def: " def_value) >> "log.sav" # MINER MOVE # if ( (m_value[1] > scout_value) && (m_value[1] >= b_value[1]) && (m_value[1] >= def_value) ) { print "***MOVING MINER***" > "/dev/stderr" print "Moving miner" >> "log.sav" print "from: " our_location_indx[miner_index[1]] " to: " miner_move[1] >> "log.sav" miner_last_move = 0 split(our_location_indx[miner_index[1]], miner_move_a, ":") split(miner_move[1], miner_move_b, ":") ++bs_last_move ++scout_last_move move_type = "miner" curr_move = miner_move_a[1]" "miner_move_a[2]" "miner_move_b[1]" "miner_move_b[2] } # SCOUT MOVE # else if ( (scout_value > m_value[1]) && (scout_value > b_value[1]) && (scout_value > def_value) ) { #new_r_c_a[1] = -1 split(our_location_indx[scout_index], sct_r_c,":") #print scout_vals[3] " " scout_vals[2] > "/dev/stderr" calc_new_row_col(sct_r_c[1], sct_r_c[2], scout_vals[3], scout_vals[2]) print "sct_r_c[1] sct_r_c[2] scout_vals[3] scout_vals[4]" >> "slog.sav" scout_last_move = 0 print "***MOVING SCOUT***" > "/dev/stderr" print "Moving Scout" >> "log.sav" print "from: " sct_r_c[1]":"sct_r_c[2] " to " new_r_c_a[1]":"new_r_c_a[2] >> "log.sav" ++bs_last_move ++miner_last_move if ( new_r_c_a[2] == 0 ) { new_r_c_a[2] += 1 } print sct_r_c[1]" "sct_r_c[2]" "new_r_c_a[1]" "new_r_c_a[2] move_type = "scout" } # BRUTE SQUAD # else if ( (b_value[1] >= m_value[1]) && (b_value[1] >= scout_value) && (b_value[1] >= def_value) ) { bs_last_move = 0 print "***MOVING BS***" > "/dev/stderr" print "Moving BS" >> "log.sav" print "from: " our_location_indx[bs_index[1]] " to: " bs_move[1] >> "log.sav" split(our_location_indx[bs_index[1]], bs_move_a, ":") split(bs_move[1], bs_move_b, ":") ++miner_last_move ++scout_last_move curr_move = bs_move_a[1]" "bs_move_a[2]" "bs_move_b[1]" "bs_move_b[2] move_type = "bs" } # DEFENSIVE MOVE # else if ( (def_value > m_value[1]) && (def_value > b_value[1]) && (def_value >= scout_value) ) { print "***MOVING DEF***" > "/dev/stderr" print "Moving Defense" >> "log.sav" print "from: " our_location_indx[defense_our_piece] " to: " defense_move_to >> "log.sav" split(our_location_indx[defense_our_piece], defense_move_a, ":") split(defense_move_to, defense_move_b, ":") ++bs_last_move ++miner_last_move ++scout_last_move curr_move = defense_move_a[1]" "defense_move_a[2]" "defense_move_b[1]" "defense_move_b[2] move_type = "def" } if ( move_type == "def" || move_type == "bs" || move_type == "miner" ) { getline saved_move < "move.sav" split( saved_move, sm, " ") split( curr_move, cm, " ") dance = cm[3]" "cm[4] dance2 = sm[1]" "sm[2] if ( dance == dance2 ) { Random_Move() } else { print curr_move > "move.sav"; print curr_move } } } # INIT_FLAG_PROBS # function Init_Flag_Probs(c, r) # this function takes no input params { print "Init_Flag_Probs" > "/dev/stderr" for(r=7; r<=10; r++) for(c=1; c<=10; c++) probability_of_flag[r,c] = 1 for (c = 2; c <= 9; c++) { probability_of_flag[10, c] = 3 probability_of_flag[9, c] = 2 } probability_of_flag[10, 1] = 5 probability_of_flag[10, 10] = 4 } # RANDOM_MOVE # # Used if the four other move functions are tied or can't come up with a move # It cycles through all of our pieces and chooses the piece closet to the flag function Random_Move(idx, new_row, ill_move, new_col) { for (idx = 39; idx >= 0; idx--) { if (our_location_indx[idx] != "-1:-1" && (our_rank_indx[idx] != "B") && (our_rank_indx[idx] != "*") ) { # try to move the first piece we can UP split(our_location_indx[idx],our_loc,":") new_row = our_loc[1] + 1 ill_move = Illegal_Move(our_loc[1], our_loc[2], 1, 1) if (ill_move != 1) { print "**********RANDOM MOVE ********************" >> "log.sav" print our_loc[1]" "our_loc[2]" "new_row" "our_loc[2] >> "log.sav" close("log.sav") print our_loc[1]" "our_loc[2]" "new_row" "our_loc[2] return 1 } # then try LEFT new_col = our_loc[2] - 1 ill_move = Illegal_Move(our_loc[1], our_loc[2], 2 ,1) if (ill_move != 1) { print "****************** RANDOM MOVE *************" >> "log.sav" print our_loc[1]" "our_loc[2]" "our_loc[1]" "new_col >> "log.sav" close("log.sav") print our_loc[1]" "our_loc[2]" "our_loc[1]" "new_col return 1 } } } return 0 } #------------------------ ------------------------------- ---------------------------------- #NOT_A_FLAG_BOMB_F: updates a not_a_flag_bomb when an enemy piece moves function not_a_flag_bomb_f( i) { print "NOT_A_FLAG_BOMB" > "/dev/stderr" for ( i=0; i < 2; i++) { getline < "recordtail" } close("recordtail") r1 = $1 c1 = $2 r2 = $3 c2 = $4 not_a_flag_bomb[r1,c1] = 1 not_a_flag_bomb[r2,c2] = 1 for (i=0; i < 2; i++) getline < "recordpenultimate" r3 = $1 c3 = $2 r4 = $3 c4 = $4 close ("recordpenultimate") not_a_flag_bomb[r3,c3] = 1 if ( my_move_action == "bomb-is-fatal") { known_bomb[r4,c4] = 1 } else { not_a_flag_bomb[r4,c4] = 1 } } #UPDATE_BOMB_PROB: updates probability_of_bomb, also cross references with not_a_flag_bomb function update_bomb_prob( x,y,combined,separate) { if ( my_move_action == "bomb-is-fatal" || my_move_action == "miner-defuses-bomb" ) { print "updating bomb probability..." > "/dev/stderr" for ( i = 0; i < 2; i++ ) { getline < "recordpenultimate" } x = $3; y = $4 probability_of_bomb[x,y] = 100 probability_of_bomb[x - 1, y] += 1 probability_of_bomb[x + 1, y] += 1 probability_of_bomb[x, y - 1] += 1 probability_of_bomb[x, y + 1] += 2 probability_of_bomb[x - 1, y - 1] += 2 probability_of_bomb[x + 1, y - 1] += 1 probability_of_bomb[x - 1, y + 1] += 1 probability_of_bomb[x - 1, y - 1] += 1 value = 0 value2 = 0 for ( i = 1; i <= 10; i++ ) { for ( j = 1; j <= 10; j++ ) { if(not_a_flag_bomb[i,j] == 1) { probability_of_bomb[i,j] = -1 } if( probability_of_bomb[i,j] > value ) { max_probability_of_bomb = i ":" j value = probability_of_bomb[i,j] } else if(probability_of_bomb[i,j] > value2 ) { second_max_probability_of_bomb = i ":" j value2 = probability_of_bomb[i,j] } } } } } # UPDATE_FLAG_PROB # function Update_Flag_Prob( r, c,front_col, back_col, left_row, right_row) # This function takes no parameters { #print "Update_Flag_Prob" > "/dev/stderr" front_col = my_col2 - 1 back_col = my_col2 + 1 left_row = my_row2 - 1 right_row = my_row2 + 1 #------------------------------------------------------- # for my_move # if ( my_move_action == "bomb-is-fatal") { #back probability_of_flag[my_row2, back_col] = probability_of_flag[my_row2, back_col] + 4 #front probability_of_flag[my_row2, front_col] = probability_of_flag[my_row2, front_col] + 1 #left probability_of_flag[left_row, my_col2] = probability_of_flag[left_row, my_col2] + 3 #right probability_of_flag[right_row, my_col2] = probability_of_flag[row_right, my_col2] + 3 #diag back right probability_of_flag[right_row, back_col] = probability_of_flag[right_row, back_col] + 3 # diag back left probability_of_flag[left_row, back_col] = probability_of_flag[left_row, back_col] + 3 #diag front left probability_of_flag[left_row, front_col] = probability_of_flag[left_row, front_col] + 1 # diag front right probability_of_flag[right_row, front_col] = probability_of_flag[right_row, front_col] + 1 } for (r = 1; r <= 10; r++) for (c = 1; c <= 10; c++) { if (not_a_flag_bomb[r,c] == 1) { probability_of_flag[r,c] = -1 } if (known_bomb[r,c] == 1 ) { probablility_of_flag[r,c] = -1 } } print " " >> "theflag.crap" for (r = 1; r<=10; r++) for (c=1; c<=10; c++) print r":"c " " probability_of_flag[r,c] >> "theflag.crap" close("theflag.crap") } #------------------------------------------------------------------------------------------- #=========================================================================================== #Sun Nov 21, 4:03am #Fixed problems with the location indices. Still have problems with calculating a new #max_prob_of_flag. Have to make sure that enemy_poss_indx is working (I believe it is) #Have to let Move Miner do its thing. What happens when we have a tie? #What happens when the "Move" functions don't return anything? Possible make another #function that scans pieces and moves closest/highest rank to the flag piece. #Wed Nov 24, 1:30pm # Added a random move function if the other move functions don't return # a valid move