-- Intervalo: script for Nomignolov, Jean M. Morales -- Start: 14/09/2k7 -- 14/09/2k7 : init -- 15/09/2k7 : complete -- 16/09/2k7 : support for repeated games -- 30/09/2k7 : a little improvement in efficiency dofile("utility_square.lua"); dofile("intervalo_algoritmos.lua"); init = function () players = {"White", "Black"}; -- Cells square_grid(8); cells[65] = "crosses_well"; cells[66] = "circles_well"; cells[67] = "neutrals_well"; cells[68] = "white_score"; cells[69] = "black_score"; cells[70] = "points_well"; -- Pieces pieces = {"crosses", "circles", "neutrals", "points"}; crosses = {}; circles = {}; neutrals = {}; points = {}; for i = 1,64 do crosses[i] = "crosses_well"; circles[i] = "circles_well"; neutrals[i] = "neutrals_well"; points[i] = "points_well"; end return 1; end victory = function () local res = 0; local finished = 1; for i = 1,64 do if (id_get_pieces(i) == -1) then finished = 0; end end -- if blocked: wins player with most points if (finished == 1) then local points_white = 0; local points_black = 0; -- TODO: types start at 0?! points_white = id_get_n_pieces_type(68, 3); points_black = id_get_n_pieces_type(69, 3); if (points_white == points_black) then res = -1; -- draw! else if (points_white > points_black) then res = 1; else res = 2; end end end return res; end list_moves = function () local move = ""; local n_move = 0; moves = {}; local s_situation = ""; local t_piece = 0; local player = id_whose_turn_is_it(); local finished = 1; for i = 1,64 do t_piece = id_get_pieces(i); if (t_piece == -1) then s_situation = s_situation .. "."; finished = 0; else if (t_piece == 3) then s_situation = s_situation .. "n"; else if (t_piece == player) then s_situation = s_situation .. "p"; else s_situation = s_situation .. "a"; end end end end if (finished == 0) then if (player == 1) then move = cells[ALG(id_alg_A, s_situation)]; n_move = 1; moves[n_move] = move; else move = cells[ALG(id_alg_B, s_situation)]; n_move = 1; moves[n_move] = move; end end return n_move; end make_move = function (move) local player = id_whose_turn_is_it(); if (player == 1) then set_flag(name_to_id(move)); else if (player == 2) then local id1 = get_flag(); local id2 = name_to_id(move); if (id1 == id2) then -- neutral piece move_piece("neutrals_well", id_get_n_pieces(67), move, 1); else -- make both moves simultanously move_piece("crosses_well", cells[id1]); move_piece("circles_well", move); local p1 = 0; local p2 = 0; local id_piece; -- update the score if (math.abs(id1, id2) > 1) then for i = math.min(id1, id2),math.max(id2, id1) do id_piece = id_get_pieces(i); if (id_piece == 1) then p1 = p1 + 1; else if (id_piece == 2) then p2 = p2 + 1; end end end if (p1 > p2) then local npw = id_get_n_pieces(70); local nws = id_get_n_pieces(68) + 1; move_piece("points_well", npw, "white_score", nws); else if (p2 > p1) then local npw = id_get_n_pieces(70); local nbs = id_get_n_pieces(69) + 1; move_piece("points_well", npw, "black_score", nbs); end end end end end end id_it_is_the_turn_of(id_next_player()); end valuation = function () val = {}; -- global val[1] = 5000; val[2] = 5000; return 2; -- 2 vals end -- info for the game game_info = function () -- the name of the game game_name = "Intervalo"; -- help for the game game_help = {}; game_help[ 1] = "TODO"; -- the author of the game game_author = "Marcos"; -- the date of birth of the game game_date = "2007?"; -- the movements of the game game_movements = {}; game_movements[ 1] = "Just click on an empty cell"; -- game's tips game_strategy = {}; game_strategy[ 1] = "?"; return 1; end init_graphics = function () board = "square.bmp"; boardw = 1; boardh = 1; square_xy_grid(); cellsx[65] = -1; cellsy[65] = -1; cellsx[66] = -1; cellsy[66] = -1; cellsx[67] = -1; cellsy[67] = -1; cellsx[68] = 1; cellsy[68] = 10; cellsx[69] = 8; cellsy[69] = 10; cellsx[70] = -1; cellsy[70] = -1; crosses_bmp = "cross.bmp"; circles_bmp = "circle.bmp"; neutrals_bmp = "yellow.bmp"; points_bmp = "mark.bmp"; id_alg_A = 0; id_alg_B = 0; local id = 0; local line = ""; local file; local msg; file, msg = io.open("PlayedGames.txt", "r"); if not file then id = 0; else for line in io.lines("PlayedGames.txt") do id = string.sub(line, 1, string.find(line, " ") - 2); end io.close(); end id = id + 0; -- print("in init"); local n_algs = 11; local n_first = 0; local n_repetitions = 100; local n_last = n_repetitions; --id = 823; -- TODO: if id = 0, 9, 19, ... print algorithms' id for x = 1,(n_algs-1) do for y = (x+1),n_algs do if ((id >= n_first) and (id < n_last)) then id_alg_A = x; id_alg_B = y; x = n_algs-1; y = n_algs; break; -- TODO: break the two "for"? end n_first = n_first + n_repetitions; n_last = n_last + n_repetitions; end end -- print("id_alg_A = " .. id_alg_A .. ", id_alg_B = " .. id_alg_B); id_alg_A = 1; id_alg_B = 5; return 1; end control_mouse = click_empty_cell;