コード例 #1
0
void
egg_editable_toolbar_set_selected (EggEditableToolbar *etoolbar,
				   GtkWidget          *widget)
{
  GtkWidget *toolbar, *toolitem;
  gboolean editable;

  etoolbar->priv->selected = widget;

  toolbar = (widget != NULL) ? gtk_widget_get_ancestor (widget, GTK_TYPE_TOOLBAR) : NULL;
  toolitem = (widget != NULL) ? gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM) : NULL;

  if(toolbar != NULL)
    {
      gint tpos = get_toolbar_position (etoolbar, toolbar);
      editable = ((egg_toolbars_model_get_flags (etoolbar->priv->model, tpos) & EGG_TB_MODEL_NOT_EDITABLE) == 0);
    }
  else
    {
      editable = FALSE;
    }

  gtk_action_set_visible (find_action (etoolbar, "RemoveToolbar"), (toolbar != NULL) && (etoolbar->priv->edit_mode > 0));
  gtk_action_set_visible (find_action (etoolbar, "RemoveToolItem"), (toolitem != NULL) && editable);
  gtk_action_set_visible (find_action (etoolbar, "MoveToolItem"), (toolitem != NULL) && editable);
}
コード例 #2
0
ファイル: net.c プロジェクト: johan--/netnuclear
/* add the recently connected client to the game as a player */
void join_player(struct socket_node *socket) {
   struct packet_version packet;
   struct packet_welcome packet2;
   int i;
   struct action_node *action;
   struct socket_node *p;
   socket->player = get_free_player();
   init_player(socket->player, INIT_PLAYER_HUMAN);
/* send version */
   packet.version = swap_int(PROGRAM_VERSION);
   send_socket(socket, PACKET_VERSION, &packet, sizeof(struct packet_version));
   
/* send welcome */
   packet2.player = swap_int(socket->player);
   send_socket(socket, PACKET_WELCOME, &packet2, sizeof(struct packet_welcome));

/* send all previous players to the new client */
   for (i = 0; i < NUM_PLAYERS; i++) {
      if (IS_ACTIVE(i) && i != socket->player) {
         send_player_info(socket, i, 0);
      /* send any already selected action */
         action = find_action(i, current_turn);
         if (action && action->action != ACTION_NOTHING)
            send_action(socket, i, current_turn);
      }
   }

/* send the new player to ALL clients */
   for (p = socket_list; p != NULL; p = p->next) {
      if (p->type == SOCKET_CLIENT)
         send_player_info(p, socket->player, 1);
   }

   telegram("\n%s has\nconnected to the server.\n", GET_NAME(socket->player));
}
コード例 #3
0
ファイル: egg-toolbar-editor.c プロジェクト: GNOME/galeon
static void
editor_drag_data_received_cb (GtkWidget          *widget,
			      GdkDragContext     *context,
			      gint                x,
			      gint                y,
			      GtkSelectionData   *selection_data,
			      guint               info,
			      guint               time_,
			      EggToolbarEditor *editor)
{
  GtkAction *action;
  const char *data;

  g_return_if_fail (EGG_IS_TOOLBAR_EDITOR (editor));
  g_return_if_fail (selection_data != NULL);

  if (selection_data->length <= 0 || selection_data->data == NULL) return;

  data = (const char *) selection_data->data;

  if (strcmp (data, "separator") == 0) return;

  action = find_action (editor, data);
  g_return_if_fail (action != NULL);

  if (g_list_find (editor->priv->default_actions_list, action))
    {
      editor->priv->actions_list = g_list_insert_sorted
	    (editor->priv->actions_list, action, compare_actions);
    }

  update_editor_sheet (editor);
}
コード例 #4
0
ファイル: players.c プロジェクト: johan--/netnuclear
void do_build(int player) {
    struct action_node *action;
    int i, rnd, num;

    action = find_action(player, current_turn);
    if (!action)
        do_error("do_build()");	/*	shouldn't happen	*/

    /* build weapons */
    for (i = 0; i < NUM_WEAPONS; i++)
        action->res_build[i] = 0;
    for (i = 0; i < randomize(3, 4); i++) {
        while (1) {
            rnd = randomize(0, NUM_WEAPONS - 1);
            if (!action->res_build[rnd]) {
                switch (rnd) {
                case WEAPON_MISSILE_10MT:
                case WEAPON_MISSILE_20MT:
                case WEAPON_MISSILE_50MT:
                case WEAPON_MISSILE_100MT:
                case WEAPON_NP1:
                case WEAPON_GR2:
                case WEAPON_LNDS:
                    num = randomize(1, 2);
                    break;
                case WEAPON_WARHEAD_10MT:
                case WEAPON_WARHEAD_20MT:
                case WEAPON_WARHEAD_50MT:
                case WEAPON_WARHEAD_100MT:
                    num = randomize(1, 3);
                    break;
                default:
                    num = 1;
                    break;
                }
                GET_STOCK(player, rnd) += num;	/*	increase stock	*/
                action->res_build[rnd] = num;	/*	remember result	*/
                break;	/*	end while-loop	*/
            }
        }
    }

    if (player == me) {
        telegram("\n%s\n", msgs_build_result[randomize(0, 1)]);
        num = 0;
        for (i = 0; i < NUM_WEAPONS; i++) {
            if (action->res_build[i]) {
                telegram(" %d %s", action->res_build[i], weapon_names[i]);
                if (action->res_build[i] > 1) {
                    if (i == WEAPON_LNDS)
                        telegram("'");
                    telegram("s");
                }
                telegram("\n");
                num++;
            }
        }
    }
}
コード例 #5
0
ファイル: players.c プロジェクト: johan--/netnuclear
/* server decides if selected actions are successful or not */
void server_prepare_actions() {
    int i, mt;
    struct action_node *action, *action2;
    struct packet_result packet;

    for (i = 0; i < NUM_PLAYERS; i++) {
        if (IS_ACTIVE(i)) {
            action = find_action(i, current_turn);
            if (action) {
                switch (action->action) {
                case ACTION_PROPAGANDA:
                    action->success = randomize(1, 1);
                    action->res_num = randomize(1, 10);	/*	population number	*/
                    break;
                case ACTION_WARHEAD_10MT:
                case ACTION_WARHEAD_20MT:
                case ACTION_WARHEAD_50MT:
                case ACTION_WARHEAD_100MT:
                    mt = action->action - ACTION_WARHEAD_10MT;
                    /* check target for defense */
                    action2 = find_action(action->target_player, current_turn);
                    if (!action2)
                        do_error("server_prepare_actions()");	/*	shouldn't happen	*/
                    if (GET_MISSILE(i) > -1 && (action2->action == ACTION_LNDS || action2->action == ACTION_MEGA))
                        action->success = 0;
                    else if (GET_BOMBER(i) > -1 && action2->action == ACTION_MEGA)
                        action->success = 0;
                    else
                        action->success = 1;
                    action->res_num = randomize(damage[mt * 2], damage[(mt * 2) + 1]);	/*	damage	*/
                    break;
                }

                /* send result to other players */
                packet.turn = swap_int(current_turn);
                packet.player = swap_int(i);
                packet.success = swap_int(action->success);
                packet.res_num = swap_int(action->res_num);
                send_all_sockets(PACKET_RESULT, &packet, sizeof(struct packet_result));
            }
        }
    }
}
コード例 #6
0
static int handle_action_request(struct device_private *priv,
                                 struct Upnp_Action_Request *ar_event)
{
	struct service *event_service;
	struct action *event_action;

	event_service = find_service(priv->upnp_device, ar_event->ServiceID);
	event_action = find_action(event_service, ar_event->ActionName);

	if (event_action == NULL) {
		fprintf(stderr, "Unknown action '%s' for service '%s'\n",
			ar_event->ActionName, ar_event->ServiceID);
		ar_event->ActionResult = NULL;
		ar_event->ErrCode = 401;
		return -1;
	}
	if (event_action->callback) {
		struct action_event event;
		int rc;
		event.request = ar_event;
		event.status = 0;
		event.service = event_service;
                event.device_priv = priv;

		rc = (event_action->callback) (&event);
		if (rc == 0) {
			ar_event->ErrCode = UPNP_E_SUCCESS;
			printf("Action '%s' was a success!\n",
			       ar_event->ActionName);
		}
		if (ar_event->ActionResult == NULL) {
			ar_event->ActionResult =
			    UpnpMakeActionResponse(ar_event->ActionName,
						   ar_event->ServiceID, 0,
						   NULL);
		}
	} else {
		fprintf(stderr,
			"Got a valid action, but no handler defined (!)\n");
		fprintf(stderr, "  ErrCode:    %d\n", ar_event->ErrCode);
		fprintf(stderr, "  Socket:     %d\n", ar_event->Socket);
		fprintf(stderr, "  ErrStr:     '%s'\n", ar_event->ErrStr);
		fprintf(stderr, "  ActionName: '%s'\n",
			ar_event->ActionName);
		fprintf(stderr, "  DevUDN:     '%s'\n", ar_event->DevUDN);
		fprintf(stderr, "  ServiceID:  '%s'\n",
			ar_event->ServiceID);
		ar_event->ErrCode = UPNP_E_SUCCESS;
	}



	return 0;
}
コード例 #7
0
ファイル: egg-toolbar-editor.c プロジェクト: GNOME/galeon
void
egg_toolbar_editor_add_action (EggToolbarEditor *editor,
			       const char       *action_name)
{
	GtkAction *action;

	action = find_action (editor, action_name);
	g_return_if_fail (action != NULL);

	editor->priv->default_actions_list = g_list_insert_sorted
		(editor->priv->default_actions_list, action, compare_actions);
}
コード例 #8
0
ファイル: players.c プロジェクト: johan--/netnuclear
void do_defense(int player) {
    struct action_node *action;

    action = find_action(player, current_turn);
    if (!action)
        do_error("do_defense()");	/*	shouldn't happen	*/

    GET_STOCK(player, WEAPON_LNDS + action->action - ACTION_LNDS)--;

    if (player == me)
        telegram("\nYou deployed a defense\nsystem to protect\nyour population.\n");
}
コード例 #9
0
ファイル: players.c プロジェクト: johan--/netnuclear
void do_missile(int player) {
    struct action_node *action;
    int mt;

    action = find_action(player, current_turn);
    if (!action)
        do_error("do_missile()");	/*	shouldn't happen	*/
    mt = action->action - ACTION_MISSILE_10MT;

    GET_STOCK(player, WEAPON_MISSILE_10MT + mt)--;	/*	decrease stock	*/

    if (player == me)
        telegram("\n%s\n%d Megatons capacity\nawaits orders.\n", missile_names[mt], megatons[mt]);
}
コード例 #10
0
ファイル: players.c プロジェクト: johan--/netnuclear
void do_bomber(int player) {
    struct action_node *action;
    int type;

    action = find_action(player, current_turn);
    if (!action)
        do_error("do_bomber()");	/*	shouldn't happen	*/
    type = action->action - ACTION_NP1;

    GET_STOCK(player, WEAPON_NP1 + type)--;	/*	decrease stock	*/
    players[player].mt_left = 50 + (50 * type);	/*	50 or 100 mt	*/

    if (player == me)
        telegram("\nBomber standing by,\n%d megatons remain.\n", players[player].mt_left);
}
コード例 #11
0
ファイル: players.c プロジェクト: johan--/netnuclear
#include "SDL.h"
#include "SDL_mixer.h"
#include "SDL_net.h"
#include "constants.h"
#include "main.h"
#include "input.h"
#include "sfx.h"
#include "misc.h"
#include "players.h"
#include "ai.h"
#include "terminal.h"
#include "world.h"
#include "net.h"
#include "packets.h"

struct Splayers players[NUM_PLAYERS];
int me;		/*	local player	*/
int recv_all_actions(int turn) {
    int i;
    struct action_node *action;

    for (i = 0; i < NUM_PLAYERS; i++) {
        if (IS_ACTIVE(i) && has_cities(i, 0)) {
            action = find_action(i, turn);
            if (!action || action->action == ACTION_NOTHING || (!server && !action->res_recv)) {
                if (!server || !players[i].ai)
                    return 0;
            }
        }
    }

    return 1;
}
コード例 #12
0
ファイル: players.c プロジェクト: johan--/netnuclear
void do_nuke(int player) {
    struct action_node *action;
    int mt, num=0;

    action = find_action(player, current_turn);
    mt = action->action - ACTION_WARHEAD_10MT;

    GET_STOCK(player, WEAPON_WARHEAD_10MT + mt)--;	/*	decrease stock	*/
    if (GET_BOMBER(player) > -1) {
        if (action->success)
            players[player].mt_left -= megatons[mt];	/*	decrease bomber capacity	*/
        else
            GET_BOMBER(player) = -1;	/*	bomber shot down	*/
    }

    if (action->success) {
        num = action->res_num;
        if (GET_POPULATION(action->target_player, action->target_city) < num)
            num = GET_POPULATION(action->target_player, action->target_city);
        GET_POPULATION(action->target_player, action->target_city) -= num;

        action->res_num = num;	/*	final result	*/
    }

    /* telegram */
    if (player == me) {
        if (GET_MISSILE(player) > -1) {
            telegram("\nThe %s\nexploded on %s.\n", missile_names[mt], GET_NAME(action->target_player));
            if (action->success)
                telegram("%d million dead.\n", num);
            else
                telegram("No casualties.\n");
        }
        else {
            telegram("\nYou bombed %s\n", GET_NAME(action->target_player));
            if (action->success && num)
                telegram("for %d million:\n", num);
            else
                telegram("for no casualties.\n");
            if (action->success)
                telegram("%d megatons remain.\n", players[me].mt_left);	/*	bomber still in air	*/
        }
    }
}
コード例 #13
0
ファイル: exec_actions.c プロジェクト: Nwazette/Zappy
bool		exec_client(fds c, double tdt)
{
  char		*s;

  s = getcmd(c);
  if (((c && (c->trick) && ((t_client*)c->trick)->close) || !fds_alive(c)) &&
      (c->write || net_close(c)))
    return (true);
  if (!(c->trick) || !(((t_client*)c->trick)->_m))
    return (mod_discovery(c, &s));
  s = flood_check(c, s);
  if (scheduler_(c, tdt))
    return (scheduler_dispatch(c));
  else if (!scheduler_active(c) && callback_(c, s, tdt))
    return (callback_handler(c, s));
  else if (s && !scheduler_active(c) && (find_action(c, s) != -1))
    flood_read(c);
  return (true);
}
コード例 #14
0
static void
configure_item_sensitivity (GtkToolItem *item, EggEditableToolbar *etoolbar)
{
  GtkAction *action;
  char *name;

  name = g_object_get_data (G_OBJECT (item), EGG_ITEM_NAME);
  action = name ? find_action (etoolbar, name) : NULL;

  if (action)
    {
      g_object_notify (G_OBJECT (action), "sensitive");
    }

  gtk_tool_item_set_use_drag_window (item,
				     (etoolbar->priv->edit_mode > 0) ||
				     GTK_IS_SEPARATOR_TOOL_ITEM (item));

}
コード例 #15
0
ファイル: players.c プロジェクト: johan--/netnuclear
void do_propaganda(int player) {
    struct action_node *action;
    int num;

    action = find_action(player, current_turn);
    if (has_cities(player, 0) && has_cities(action->target_player, 0))
        num = action->res_num;	/*	population number set by server	*/
    else
        num = 0;	/*	player or target player is defeated	*/

    if (action->success) {
        action->res_city = get_smallest_city(player);	/*	remember for next_player()	*/
        /* do increase/decrease */
        if (GET_POPULATION(action->target_player, action->target_city) < num)
            num = GET_POPULATION(action->target_player, action->target_city);
        GET_POPULATION(action->target_player, action->target_city) -= num;
        GET_POPULATION(player, action->res_city) += num;

        if (player == me) {
            telegram("\nAfter a propaganda\nstrike, ");
            if (num)
                telegram("%d million", num);
            else
                telegram("No one");
            telegram(" left\n%s for you.\n", GET_NAME(action->target_player));
        }
    }
    else {
        /* remember for next_player() */
        action->res_city = get_biggest_city(player);
        action->res_target_city = get_smallest_city(action->target_player);
        /* do increase/decrease */
        if (GET_POPULATION(player, action->res_city) < num)
            num = GET_POPULATION(player, action->res_city);
        GET_POPULATION(player, action->res_city) -= num;
        GET_POPULATION(action->target_player, action->res_target_city) += num;

        if (player == me)
            telegram("\nYour propaganda strike\nfailed. %d million\ndefected to %s.\n", num, GET_NAME(action->target_player));
    }

    action->res_num = num;	/*	final result	*/
}
コード例 #16
0
ファイル: cfg_param.c プロジェクト: p1rate5s/c-icap
int process_line(char *line){
     int i=0;
     char *str,*args,**argv=NULL;
     struct conf_entry *entry;

     str=line;
     while(*str!='\0' && isspace(*str)) /*Eat the spaces in the begging*/
	  str++;
     if(*str=='\0' || *str=='#') /*Empty line or comment*/
	  return 0;
     
     entry=find_action(str,&args);
//     debug_printf(10,"Line %s (Args:%s)\n",entry->name,args);
     
     if(entry && entry->action){
	  argv=split_args(args);
	  (*(entry->action))(entry->name,argv,entry->data);
	  free_args(argv);
	  return 1;/*OK*/
     }
     //Else parse error.......
     //Log an error.....
     return 0;
}
コード例 #17
0
static GtkToolItem *
create_item_from_action (EggEditableToolbar *etoolbar,
			 const char *name)
{
  GtkToolItem *item;

  g_return_val_if_fail (name != NULL, NULL);

  if (strcmp (name, "_separator") == 0)
    {
      item = gtk_separator_tool_item_new ();
    }
  else
    {
      GtkAction *action = find_action (etoolbar, name);
      if (action == NULL) return NULL;

      item = GTK_TOOL_ITEM (gtk_action_create_tool_item (action));

      /* Normally done on-demand by the GtkUIManager, but no
       * such demand may have been made yet, so do it ourselves.
       */
      gtk_action_set_accel_group
        (action, gtk_ui_manager_get_accel_group(etoolbar->priv->manager));

      g_signal_connect_object (action, "notify::sensitive",
                               G_CALLBACK (action_sensitive_cb), item, 0);
    }

  gtk_widget_show (GTK_WIDGET (item));

  g_object_set_data_full (G_OBJECT (item), EGG_ITEM_NAME,
                          g_strdup (name), g_free);

  return item;
}
コード例 #18
0
ファイル: utils.c プロジェクト: KevenChang/pacemaker
static void
print_synapse(unsigned int log_level, crm_graph_t * graph, synapse_t * synapse)
{
    GListPtr lpc = NULL;
    char *pending = NULL;
    const char *state = "Pending";

    if (synapse->failed) {
        state = "Failed";

    } else if (synapse->confirmed) {
        state = "Completed";

    } else if (synapse->executed) {
        state = "In-flight";

    } else if (synapse->ready) {
        state = "Ready";
    }

    if (synapse->executed == FALSE) {
        for (lpc = synapse->inputs; lpc != NULL; lpc = lpc->next) {
            crm_action_t *input = (crm_action_t *) lpc->data;
            const char *id_string = crm_element_value(input->xml, XML_ATTR_ID);

            if (input->failed) {
                pending = add_list_element(pending, id_string);

            } else if (input->confirmed) {
                /* Confirmed, skip */

            } else if (find_action(graph, input->id)) {
                /* In-flight or pending */
                pending = add_list_element(pending, id_string);
            }
        }
    }

    for (lpc = synapse->actions; lpc != NULL; lpc = lpc->next) {
        crm_action_t *action = (crm_action_t *) lpc->data;
        const char *key = crm_element_value(action->xml, XML_LRM_ATTR_TASK_KEY);
        const char *host = crm_element_value(action->xml, XML_LRM_ATTR_TARGET);
        char *desc = crm_strdup_printf("%s %s op %s", state, actiontype2text(action->type), key);

        do_crm_log(log_level,
                   "[Action %4d]: %-50s on %s (priority: %d, waiting: %s)",
                   action->id, desc, host ? host : "N/A",
                   synapse->priority, pending ? pending : "none");

        free(desc);
    }

    if (synapse->executed == FALSE) {
        for (lpc = synapse->inputs; lpc != NULL; lpc = lpc->next) {
            crm_action_t *input = (crm_action_t *) lpc->data;
            const char *key = crm_element_value(input->xml, XML_LRM_ATTR_TASK_KEY);
            const char *host = crm_element_value(input->xml, XML_LRM_ATTR_TARGET);

            if (find_action(graph, input->id) == NULL) {
                if (host == NULL) {
                    do_crm_log(log_level, " * [Input %2d]: Unresolved dependency %s op %s",
                               input->id, actiontype2text(input->type), key);
                } else {
                    do_crm_log(log_level, " * [Input %2d]: Unresolved dependency %s op %s on %s",
                               input->id, actiontype2text(input->type), key, host);
                }
            }
        }
    }

    free(pending);
}
コード例 #19
0
static GtkWidget *
editor_create_item_from_name (EggToolbarEditor *editor,
                              const char *      name,
                              GdkDragAction     drag_action)
{
  GtkWidget *item;
  const char *item_name;
  char *short_label;
  const char *collate_key;

  if (strcmp (name, "_separator") == 0)
    {
      GtkWidget *icon;

      icon = _egg_editable_toolbar_new_separator_image ();
      short_label = _("Separator");
      item_name = g_strdup (name);
      collate_key = g_utf8_collate_key (short_label, -1);
      item = editor_create_item (editor, GTK_IMAGE (icon),
                                 short_label, drag_action);
    }
  else
    {
      GtkAction *action;
      GtkWidget *icon;
      char *stock_id, *icon_name = NULL;

      action = find_action (editor, name);
      g_return_val_if_fail (action != NULL, NULL);

      g_object_get (action,
                    "icon-name", &icon_name,
                    "stock-id", &stock_id,
		    "short-label", &short_label,
		    NULL);

      /* This is a workaround to catch named icons. */
      if (icon_name)
        icon = gtk_image_new_from_icon_name (icon_name,
	                                     GTK_ICON_SIZE_LARGE_TOOLBAR);
      else
        icon = gtk_image_new_from_stock (stock_id ? stock_id : GTK_STOCK_DND,
                                         GTK_ICON_SIZE_LARGE_TOOLBAR);

      item_name = g_strdup (name);
      collate_key = g_utf8_collate_key (short_label, -1);
      item = editor_create_item (editor, GTK_IMAGE (icon),
                                 short_label, drag_action);

      g_free (short_label);
      g_free (stock_id);
      g_free (icon_name);
    }

  g_object_set_data_full (G_OBJECT (item), "egg-collate-key",
                          (gpointer) collate_key, g_free);
  g_object_set_data_full (G_OBJECT (item), "egg-item-name",
                          (gpointer) item_name, g_free);

  return item;
}
コード例 #20
0
ファイル: players.c プロジェクト: johan--/netnuclear
/* execute selected actions */
void do_actions() {
    int i, missile, bomber, i2;
    struct action_node *action;

    for (i = 0; i < NUM_PLAYERS; i++) {
        if (IS_ACTIVE(i)) {
            action = find_action(i, current_turn);
            if (action) {
                missile = -1;
                bomber = -1;
                switch (action->action) {
                case ACTION_BUILD:
                    if (has_cities(i, 0))
                        do_build(i);
                    break;
                case ACTION_PROPAGANDA:
                    if (has_cities(i, 0)) {
                        do_propaganda(i);
                        /* random message */
                        if (i == me && players[action->target_player].ai)
                            ai_random_message(action->target_player);
                    }
                    break;
                case ACTION_MISSILE_10MT:
                case ACTION_MISSILE_20MT:
                case ACTION_MISSILE_50MT:
                case ACTION_MISSILE_100MT:
                    if (has_cities(i, 0)) {
                        do_missile(i);
                        missile = action->action - ACTION_MISSILE_10MT;
                    }
                    break;
                case ACTION_WARHEAD_10MT:
                case ACTION_WARHEAD_20MT:
                case ACTION_WARHEAD_50MT:
                case ACTION_WARHEAD_100MT:
                    do_nuke(i);
                    if (!players[i].ai)
                        bomber = GET_BOMBER(i);	/*	don't unset so we can reuse the bomber	*/
                    else {
                        if (players[i].mt_left) {
                            /* check if the ai player has a warhead and enough capacity to reuse the bomber */
                            for (i2 = 0; i2 < 4; i2++) {
                                if (GET_STOCK(i, WEAPON_WARHEAD_10MT + i2) && megatons[i2] <= players[i].mt_left)
                                    bomber = GET_BOMBER(i);
                            }
                        }
                    }
                    /* random message */
                    if (i == me && players[action->target_player].ai && has_cities(me, 0))
                        ai_random_message(action->target_player);
                    break;
                case ACTION_NP1:
                case ACTION_GR2:
                    if (has_cities(i, 0)) {
                        do_bomber(i);
                        bomber = action->action - ACTION_NP1;
                    }
                    break;
                case ACTION_LNDS:
                case ACTION_MEGA:
                    if (has_cities(i, 0))
                        do_defense(i);
                    break;
                }

                GET_PREVIOUS(i) = action->action;	/*	remember action for next turn	*/
                GET_MISSILE(i) = missile;
                GET_BOMBER(i) = bomber;
            }
        }
    }
}
コード例 #21
0
static int handle_action_request(struct upnp_device *priv,
                                 struct Upnp_Action_Request *ar_event)
{
	struct service *event_service;
	struct action *event_action;

	event_service = find_service(priv->upnp_device_descriptor,
				     ar_event->ServiceID);
	event_action = find_action(event_service, ar_event->ActionName);

	if (event_action == NULL) {
		Log_error("upnp", "Unknown action '%s' for service '%s'",
			  ar_event->ActionName, ar_event->ServiceID);
		ar_event->ActionResult = NULL;
		ar_event->ErrCode = 401;
		return -1;
	}

	// We want to send the LastChange event only after the action is
	// finished - just to be conservative, we don't know how clients
	// react to get LastChange notifictions while in the middle of
	// issuing an action.
	//
	// So we nest the change collector level here, so that we only send the
	// LastChange after the action is finished ().
	//
	// Note, this is, in fact, only a preparation and not yet working as
	// described above: we are still in the middle
	// of executing the event-callback while sending the last change
	// event implicitly when calling UPnPLastChangeCollector_finish() below.
	// It would be good to enqueue the upnp_device_notify() after
	// the action event is finished.
	if (event_service->last_change) {
		ithread_mutex_lock(event_service->service_mutex);
		UPnPLastChangeCollector_start(event_service->last_change);
		ithread_mutex_unlock(event_service->service_mutex);
	}

#ifdef ENABLE_ACTION_LOGGING
	{
		char *action_request_xml = NULL;
		if (ar_event->ActionRequest) {
			action_request_xml = ixmlDocumenttoString(
					   ar_event->ActionRequest);
		}
		Log_info("upnp", "Action '%s'; Request: %s",
			 ar_event->ActionName, action_request_xml);
		free(action_request_xml);
	}
#endif

	if (event_action->callback) {
		struct action_event event;
		int rc;
		event.request = ar_event;
		event.status = 0;
		event.service = event_service;
                event.device = priv;

		rc = (event_action->callback) (&event);
		if (rc == 0) {
			ar_event->ErrCode = UPNP_E_SUCCESS;
#ifdef ENABLE_ACTION_LOGGING
			if (ar_event->ActionResult) {
				char *action_result_xml = NULL;
				action_result_xml = ixmlDocumenttoString(
						ar_event->ActionResult);
				Log_info("upnp", "Action '%s' OK; Response %s",
					 ar_event->ActionName,
					 action_result_xml);
				free(action_result_xml);
			} else {
				Log_info("upnp", "Action '%s' OK",
					 ar_event->ActionName);
			}
#endif
		}
		if (ar_event->ActionResult == NULL) {
			ar_event->ActionResult =
			    UpnpMakeActionResponse(ar_event->ActionName,
						   event_service->service_type,
						   0, NULL);
		}
	} else {
		Log_error("upnp",
			  "Got a valid action, but no handler defined (!)\n"
			  "  ErrCode:    %d\n"
			  "  Socket:     %d\n"
			  "  ErrStr:     '%s'\n"
			  "  ActionName: '%s'\n"
			  "  DevUDN:     '%s'\n"
			  "  ServiceID:  '%s'\n",
			  ar_event->ErrCode, ar_event->Socket, ar_event->ErrStr,
			  ar_event->ActionName, ar_event->DevUDN,
			  ar_event->ServiceID);
		ar_event->ErrCode = UPNP_E_SUCCESS;
	}

	if (event_service->last_change) {   // See comment above.
		ithread_mutex_lock(event_service->service_mutex);
		UPnPLastChangeCollector_finish(event_service->last_change);
		ithread_mutex_unlock(event_service->service_mutex);
	}
	return 0;
}
コード例 #22
0
ファイル: ai.c プロジェクト: despley/BlueMoonMac
/*
 * Return a string containing the AI's assumption about the best possible
 * move.
 */
void ai_assist(game *g, char *buf)
{
	game sim;
	action current;
	char tmp[1024];

	/* Clear best path */
	best_path_pos = 0;
	best_path_score = -1;

	/* Simulate game */
	simulate_game(&sim, g);

	/* Find best action path */
	find_action(&sim);

	/* Check for no legal moves */
	if (best_path_score == -1)
	{
		/* Add message */
		strcpy(buf, "No legal moves!\n");
		return;
	}

	/* Start back at beginning */
	simulate_game(&sim, g);

	/* Clear buffer */
	strcpy(buf, "");

	/* Use buffer for assist messages */
	assist_str = buf;

	/* Start at beginning of path */
	best_path_pos = 0;

	/* Loop until done */
	while (sim.p[g->turn].phase <= PHASE_ANNOUNCE)
	{
		/* Get current action */
		current = best_path[best_path_pos];

		/* Advance position */
		best_path_pos++;

		/* Check current action */
		switch (current.act)
		{
			/* None */
			case ACT_NONE:

				/* No message */
				strcpy(tmp, "");
				break;

			/* Retreat */
			case ACT_RETREAT:

				/* Add message */
				sprintf(tmp, "Retreat\n");
				break;

			/* Retrieve */
			case ACT_RETRIEVE:

				/* Add message */
				sprintf(tmp, "Retrieve %s\n",
				             current.arg->name);
				break;

			/* Play */
			case ACT_PLAY:

				/* Add message */
				sprintf(tmp, "Play %s\n",
				              current.arg->name);
				break;

			/* Play with no effect */
			case ACT_PLAY_NO:

				/* Add message */
				sprintf(tmp, "Play %s with no effect\n",
				              current.arg->name);
				break;

			/* Announce fire */
			case ACT_ANN_FIRE:

				/* Add message */
				sprintf(tmp, "Announce fire\n");
				break;

			/* Announce earth */
			case ACT_ANN_EARTH:

				/* Add message */
				sprintf(tmp, "Announce earth\n");
				break;

			/* Use special */
			case ACT_USE:

				/* Add message */
				sprintf(tmp, "Use %s special text\n",
				              current.arg->name);
				break;

			/* Satisfy */
			case ACT_SATISFY:

				/* Add message */
				sprintf(tmp, "Satisfy %s\n",
				              current.arg->name);
				break;

			/* Land ship */
			case ACT_LAND:

				/* Add message */
				sprintf(tmp, "Land %s\n",
				              current.arg->name);
				break;

			/* Load ship */
			case ACT_LOAD:

				/* Add message */
				sprintf(tmp, "Load %s onto %s\n",
				              current.arg->name,
				              current.target->name);
				break;

			/* Play bluff */
			case ACT_BLUFF:

				/* Add message */
				sprintf(tmp, "Bluff %s\n",
				              current.arg->name);
				break;

			/* Reveal bluff */
			case ACT_REVEAL:

				/* Add message */
				sprintf(tmp, "Reveal %s\n",
				              current.arg->name);
				break;
		}

		/* Add message to buffer */
		strcat(buf, tmp);

		/* Perform action */
		perform_act(&sim, current);

		/* Check for retreat */
		if (current.act == ACT_RETREAT) break;

		/* Check for game over */
		if (sim.game_over) break;
	}

	/* Clear assist string */
	assist_str = NULL;
}
コード例 #23
0
static void
toolbar_visibility_refresh (EggEditableToolbar *etoolbar)
{
  EggEditableToolbarPrivate *priv = etoolbar->priv;
  gint n_toolbars, n_items, i, j, k;
  GtkToggleAction *action;
  GList *list;
  GString *string;
  gboolean showing;
  char action_name[40];
  char *action_label;
  char *tmp;

  if (priv == NULL || priv->model == NULL || priv->manager == NULL ||
      priv->visibility_paths == NULL || priv->actions == NULL)
    {
      return;
    }

  if (priv->visibility_actions == NULL)
    {
      priv->visibility_actions = g_ptr_array_new ();
    }

  if (priv->visibility_id != 0)
    {
      gtk_ui_manager_remove_ui (priv->manager, priv->visibility_id);
    }

  priv->visibility_id = gtk_ui_manager_new_merge_id (priv->manager);

  showing = gtk_widget_get_visible (GTK_WIDGET (etoolbar));

  n_toolbars = egg_toolbars_model_n_toolbars (priv->model);
  for (i = 0; i < n_toolbars; i++)
    {
      string = g_string_sized_new (0);
      n_items = egg_toolbars_model_n_items (priv->model, i);
      for (k = 0, j = 0; j < n_items; j++)
        {
          GValue value = { 0, };
          GtkAction *action;
          const char *name;

          name = egg_toolbars_model_item_nth (priv->model, i, j);
          if (name == NULL) continue;
          action = find_action (etoolbar, name);
          if (action == NULL) continue;

          g_value_init (&value, G_TYPE_STRING);
          g_object_get_property (G_OBJECT (action), "label", &value);
          name = g_value_get_string (&value);
          if (name == NULL)
	    {
		g_value_unset (&value);
		continue;
	    }
	  k += g_utf8_strlen (name, -1) + 2;
	  if (j > 0)
	    {
	      g_string_append (string, ", ");
	      if (j > 1 && k > 25)
		{
		  g_value_unset (&value);
		  break;
		}
	    }
	  g_string_append (string, name);
	  g_value_unset (&value);
	}
      if (j < n_items)
        {
	  g_string_append (string, " ...");
        }

      tmp = g_string_free (string, FALSE);
      for (j = 0, k = 0; tmp[j]; j++)
      {
	if (tmp[j] == '_') continue;
	tmp[k] = tmp[j];
	k++;
      }
      tmp[k] = 0;
      /* Translaters: This string is for a toggle to display a toolbar.
       * The name of the toolbar is automatically computed from the widgets
       * on the toolbar, and is placed at the %s. Note the _ before the %s
       * which is used to add mnemonics. We know that this is likely to
       * produce duplicates, but don't worry about it. If your language
       * normally has a mnemonic at the start, please use the _. If not,
       * please remove. */
      action_label = g_strdup_printf (_("Show “_%s”"), tmp);
      g_free (tmp);

      sprintf(action_name, "ToolbarToggle%d", i);

      if (i >= priv->visibility_actions->len)
        {
	  action = gtk_toggle_action_new (action_name, action_label, NULL, NULL);
	  g_ptr_array_add (priv->visibility_actions, action);
	  g_signal_connect_object (action, "toggled",
				   G_CALLBACK (toggled_visibility_cb),
				   etoolbar, 0);
	  gtk_action_group_add_action (priv->actions, GTK_ACTION (action));
	}
      else
        {
	  action = g_ptr_array_index (priv->visibility_actions, i);
	  g_object_set (action, "label", action_label, NULL);
        }

      gtk_action_set_visible (GTK_ACTION (action), (egg_toolbars_model_get_flags (priv->model, i)
						    & EGG_TB_MODEL_NOT_REMOVABLE) == 0);
      gtk_action_set_sensitive (GTK_ACTION (action), showing);
      gtk_toggle_action_set_active (action, gtk_widget_get_visible
				    (get_dock_nth (etoolbar, i)));

      for (list = priv->visibility_paths; list != NULL; list = g_list_next (list))
        {
	  gtk_ui_manager_add_ui (priv->manager, priv->visibility_id,
				 (const char *)list->data, action_name, action_name,
				 GTK_UI_MANAGER_MENUITEM, FALSE);
	}

      g_free (action_label);
    }

  gtk_ui_manager_ensure_update (priv->manager);

  while (i < priv->visibility_actions->len)
    {
      action = g_ptr_array_index (priv->visibility_actions, i);
      g_ptr_array_remove_index_fast (priv->visibility_actions, i);
      gtk_action_group_remove_action (priv->actions, GTK_ACTION (action));
      i++;
    }
}
コード例 #24
0
static void
configure_item_cursor (GtkToolItem *item,
		       EggEditableToolbar *etoolbar)
{
  EggEditableToolbarPrivate *priv = etoolbar->priv;
  GtkWidget *widget = GTK_WIDGET (item);

  if (gtk_widget_get_window (widget) != NULL)
    {
      if (priv->edit_mode > 0)
        {
          GdkCursor *cursor;
	  GdkScreen *screen;
          GdkPixbuf *pixbuf = NULL;

	  screen = gtk_widget_get_screen (GTK_WIDGET (etoolbar));

          cursor = gdk_cursor_new_for_display (gdk_screen_get_display (screen),
					       GDK_HAND2);
          gdk_window_set_cursor (gtk_widget_get_window (widget), cursor);
          gdk_cursor_unref (cursor);

          gtk_drag_source_set (widget, GDK_BUTTON1_MASK, dest_drag_types,
                               G_N_ELEMENTS (dest_drag_types), GDK_ACTION_MOVE);
          if (GTK_IS_SEPARATOR_TOOL_ITEM (item))
            {
              pixbuf = new_separator_pixbuf ();
            }
          else
            {
              char *icon_name=NULL;
              char *stock_id=NULL;
              GtkAction *action;
              char *name;

              name = g_object_get_data (G_OBJECT (widget), EGG_ITEM_NAME);
              action = name ? find_action (etoolbar, name) : NULL;

              if (action)
                {
                   g_object_get (action,
                                 "icon-name", &icon_name,
                                 "stock-id", &stock_id,
                                 NULL);
                }
              if (icon_name)
                {
                  GdkScreen *screen;
                  GtkIconTheme *icon_theme;
                  GtkSettings *settings;
                  gint width, height;

                  screen = gtk_widget_get_screen (widget);
                  icon_theme = gtk_icon_theme_get_for_screen (screen);
                  settings = gtk_settings_get_for_screen (screen);

                  if (!gtk_icon_size_lookup_for_settings (settings,
                                                          GTK_ICON_SIZE_LARGE_TOOLBAR,
                                                          &width, &height))
                    {
                      width = height = 24;
                    }

                  pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name,
                                                     MIN (width, height), 0, NULL);
                }
              else if (stock_id)
                {
                  pixbuf = gtk_widget_render_icon (widget, stock_id,
	                                           GTK_ICON_SIZE_LARGE_TOOLBAR, NULL);
                }
              g_free (icon_name);
              g_free (stock_id);
            }

          if (G_UNLIKELY (!pixbuf))
            {
              return;
            }
          gtk_drag_source_set_icon_pixbuf (widget, pixbuf);
          g_object_unref (pixbuf);

        }
      else
        {
          gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET(item)), NULL);
        }
    }
}
コード例 #25
0
ファイル: ai.c プロジェクト: despley/BlueMoonMac
/*
 * Handle a choice to be made.
 */
static double choose_action(game *g)
{
	game sim;
	design *list[DECK_SIZE], **choices;
	node *n_ptr;
	void *data;
	double score, b_s = -1;
	int old_turn;
	int best_combo = 0;
	int i, j, num_chosen;

	/* Get current player's turn */
	old_turn = g->turn;

	/* Get pointer to choice node */
	n_ptr = &nodes[node_pos];

	/* Track current choice node */
	node_pos++;
	best_path_pos++;

	/* Loop over choices */
	for (i = 0; i < n_ptr->num_legal; i++)
	{
		/* Avoid unnecessary work when checking for forced retreat */
		if (checking_retreat && !must_retreat) break;

		/* Clear number chosen */
		num_chosen = 0;

		/* Get choice list */
		choices = n_ptr->choices;

		/* Get callback data */
		data = n_ptr->data;

		/* Loop over combination */
		for (j = 0; (1 << j) <= n_ptr->legal[i]; j++)
		{
			/* Check for bit set */
			if (n_ptr->legal[i] & (1 << j))
			{
				/* Add choice to list */
				list[num_chosen++] = choices[j];
			}
		}

#ifdef DEBUG
		/* Remember current path */
		cur_path[best_path_pos].act = ACT_CHOOSE;
		cur_path[best_path_pos].chosen = n_ptr->legal[i];
#endif

		/* Simulate game */
		simulate_game(&sim, g);

		/* Make choice */
		if (!n_ptr->callback(&sim, n_ptr->who, list, num_chosen, data))
		{
			printf("Callback failed!\n");
		}

		/* Check for turn change */
		if (sim.turn != old_turn)
		{
			/* Are we checking forced retreat */
			if (checking_retreat)
			{
				/* Score is unimportant */
				score = 0;
			}
			else
			{
				/* Assume worst-case response from opponent */
				score = check_decline(&sim, sim.sim_turn);
			}
		}
		else
		{
			/* Continue searching */
			score = find_action(&sim);
		}

		/* Check for better score among actions */
		if (score >= b_s)
		{
			/* Remember best */
			b_s = score;
			best_combo = n_ptr->legal[i];
		}
	}

	/* Remove node from list */
	node_pos--;
	node_len--;

	/* Return to current path position */
	best_path_pos--;

	/* Check for better actions than previously discovered */
	if (!checking_retreat && b_s >= best_path_score)
	{
		/* Store action in best path */
		best_path[best_path_pos].act = ACT_CHOOSE;
		best_path[best_path_pos].chosen = best_combo;

		/* Save best score seen */
		best_path_score = b_s;
	}

	/* Return best score */
	return b_s;
}
コード例 #26
0
ファイル: ai.c プロジェクト: despley/BlueMoonMac
/*
 * Find the best "action path" available from the given state.
 *
 * We also return the score of the endstate that will result.
 *
 * We return -1 if no legal actions are available.
 *
 * This function is recursive.
 */
static double find_action(game *g)
{
	game sim;
	player *p;
	int old_turn;
	int i, n;
	action legal[MAX_ACTION], best_act;
	double score, b_s = -1;

	/* Get player pointer */
	p = &g->p[g->turn];

	/* Get current player's turn */
	old_turn = g->turn;

	/* Check for game over */
	if (g->game_over)
	{
		/* Clear any choice nodes that haven't been examined */
		node_len = node_pos;

		/* Return end of game score */
		return eval_game(g, g->sim_turn);
	}

	/* Check for choice to make */
	if (node_pos < node_len)
	{
		/* Handle choice node instead of normal */
		return choose_action(g);
	}

	/* Avoid needlees work when checking for forced retreat */
	if (checking_retreat && !must_retreat) return 0;

	/* Get legal actions to take */
	n = legal_act(g, legal);

	/* Check for no legal actions */
	if (!n) return -1;

	/* Check for only one possible action */
	if (n == 1)
	{
		/* Increase path position for future searching */
		best_path_pos++;

#ifdef DEBUG
		/* Remember current path */
		cur_path[best_path_pos] = legal[0];
#endif

		/* Perform that action */
		perform_act(g, legal[0]);

		/* Check for turn change */
		if (g->turn != old_turn)
		{
			/* Are we checking opponent's response */
			if (checking_retreat)
			{
				/* Score is unimportant */
				score = 0.0;

				/* We must not be forced to retreat */
				must_retreat = 0;
			}
			else
			{
				/* Check for inevitable retreat from opponent */
				check_retreat(g);

				/* Get score */
				score = eval_game(g, g->sim_turn);

				/* Clear must retreat flag */
				must_retreat = 0;
			}
		}

		/* Continue searching */
		else score = find_action(g);

		/* Return to current path position */
		best_path_pos--;

		/* Check for better actions than previously discovered */
		if (!checking_retreat && score >= best_path_score)
		{
			/* Store action in best path */
			best_path[best_path_pos] = legal[0];

			/* Save best score seen */
			best_path_score = score;
		}

		/* Return score */
		return score;
	}

	/* Increase path position for future searching */
	best_path_pos++;

	/* Loop over available actions */
	for (i = 0; i < n; i++)
	{
#ifdef DEBUG
		/* Remember current path */
		cur_path[best_path_pos] = legal[i];
#endif

		/* Avoid unnecessary work when checking for forced retreat */
		if (checking_retreat && !must_retreat) break;

		/* Copy game */
		simulate_game(&sim, g);

		/* Perform action */
		perform_act(&sim, legal[i]);

		/* Check for retreat */
		if (legal[i].act == ACT_RETREAT && node_pos == node_len)
		{
			/* Are we checking for forced retreat */
			if (checking_retreat)
			{
				/* Score is unimportant */
				score = 0;
			}
			else
			{
				/* Get score */
				score = eval_game(&sim, sim.sim_turn);
			}
		}

		/* Normal action */
		else
		{
			/* Continue searching */
			score = find_action(&sim);
		}

		/* Check for better score among actions */
		if (score >= b_s)
		{
			/* Remember best */
			b_s = score;
			best_act = legal[i];
		}
	}

	/* Return to current path position */
	best_path_pos--;

	/* Check for better actions than previously discovered */
	if (!checking_retreat && b_s >= best_path_score)
	{
		/* Store action in best path */
		best_path[best_path_pos] = best_act;

		/* Save best score seen */
		best_path_score = b_s;
	}

	/* Return best score */
	return b_s;
}
コード例 #27
0
int yyparse( void )
{
    short yypnum;
    short yyi, yylhs;
    YYACTTYPE yyaction;
    YYTOKENTYPE yytoken;
    YYACTTYPE yys[MAXDEPTH], *yysp;
    YYSTYPE yyv[MAXDEPTH], *yyvp;
    short yyerrflag;

    yyerrflag = 0;
    yysp = yys;
    yyvp = yyv;
    *yysp = YYSTART;
    yytoken = yylex();
    for( ;; ) {
yynewact:
        yyaction = find_action( *yysp, yytoken );
        if( yyaction == YYNOACTION ) {
            yyaction = find_action( *yysp, YYDEFTOKEN );
            if( yyaction == YYNOACTION ) {
                switch( yyerrflag ) {
                case 0:
                    yyerror( "syntax error" );
                    YYERROR;
yyerrlab:
                case 1:
                case 2:
                    yyerrflag = 3;
                    while( yysp >= yys ) {
                        yyaction = find_action( *yysp, YYERRTOKEN );
                        if( yyaction != YYNOACTION && yyaction < YYUSED ) {
                            *++yysp = yyaction;
                            ++yyvp;
                            goto yynewact;
                        }
                        --yysp;
                        --yyvp;
                    }
                    YYABORT;
                case 3:
                    if( yytoken == YYEOFTOKEN )
                        YYABORT;
                    yytoken = yylex();
                    goto yynewact;
                }
            }
        }
        if( yyaction < YYUSED ) {
            if( yyaction == YYSTOP ) {
                YYACCEPT;
            }
            *++yysp = yyaction;
            *++yyvp = yylval;
            if( yyerrflag )
                --yyerrflag;
            yytoken = yylex();
        } else {
            yypnum = yyaction - YYUSED;
            yyi = yyplentab[yypnum];
            yysp -= yyi;
            yyvp -= yyi;
            yylhs = yyplhstab[yypnum];
            if( yysp < yys ) {
                printf( "stack underflow\n" );
                YYABORT;
            }
            yyaction = find_action( *yysp, yylhs );
            if( yyaction == YYNOACTION ) {
                printf( "missing nonterminal\n" );
                YYABORT;
            }
            *++yysp = yyaction;
            ++yyvp;
            switch( yypnum ) {

            default:
                yyval = yyvp[0];
            }
            *yyvp = yyval;
        }
    }
}
コード例 #28
0
ファイル: ai.c プロジェクト: despley/BlueMoonMac
/*
 * Check if current player must retreat.
 *
 * We run this check from the point of view of the opponent.
 *
 * If current player must retreat, simulate the results.
 */
static void check_retreat(game *g)
{
	game sim;
	player *p, *opp;
	card *c;
	int i;
	int all_known = 1, moved = 0, bluff = 0;

	/* Do nothing if no fight to retreat from */
	if (!g->fight_started) return;

	/* Get opponent pointer */
	opp = &g->p[!g->turn];

	/* Loop over opponent cards */
	for (i = 1; i < DECK_SIZE; i++)
	{
		/* Get card pointer */
		c = &opp->deck[i];

		/* Skip inactive cards */
		if (!c->active) continue;

		/* Check for bluff card */
		if (c->bluff) bluff = 1;

		/* Skip cards with text ignored */
		if (c->text_ignored) continue;

		/* Skip cards without category 3 special text */
		if (c->d_ptr->special_cat != 3) continue;

		/* Skip cards that don't disallow calling bluff */
		if (c->d_ptr->special_effect !=(S3_YOU_MAY_NOT | S3_CALL_BLUFF))
			continue;

		/* Assume no bluff cards are in play */
		bluff = 0;
		break;
	}

	/* Do not check for forced retreat if bluff may be called */
	if (bluff) return;

	/* Simulate game */
	simulate_game(&sim, g);

	/* Get player pointer */
	p = &sim.p[sim.turn];

	/* Loop over cards */
	for (i = 1; i < DECK_SIZE; i++)
	{
		/* Get card pointer */
		c = &p->deck[i];

		/* Skip cards not in hand */
		if (c->where != LOC_HAND) continue;

		/* Check for unknown card */
		if (!c->loc_known) all_known = 0;
	}

	/* Check for not all cards in hand known */
	if (!all_known)
	{
		/* Pretend all unknown cards are in hand */
		for (i = 1; i < DECK_SIZE; i++)
		{
			/* Get card pointer */
			c = &p->deck[i];

			/* Skip cards with known locations */
			if (c->loc_known && !c->random_fake) continue;

			/* Clear "random" flag */
			c->random_fake = 0;

			/* Move card to hand */
			c->where = LOC_HAND;

			/* Count cards moved */
			moved++;
		}
	}

	/* XXX Do nothing if most cards moved */
	if (moved > 15) return;

	/* Set retreat flag */
	must_retreat = 1;
	checking_retreat = 1;

	/* Simulate possible actions */
	find_action(&sim);

	/* Check for retreat flag still set */
	if (must_retreat)
	{
		/* Force current player to retreat before evaluating score */
		retreat(g);
	}

	/* Clear retreat check flag */
	checking_retreat = 0;
}
コード例 #29
0
ファイル: ai.c プロジェクト: despley/BlueMoonMac
/*
 * Decide whether to call bluff.
 */
static int ai_call_bluff(game *g)
{
	game sim;
	player *opp;
	card *c;
	double score;
	int i, unknown = 0, bluff = 0;

	/* Get bluffing player's pointer (it is still their turn) */
	opp = &g->p[g->turn];

	/* Loop over opponent cards */
	for (i = 1; i < DECK_SIZE; i++)
	{
		/* Get card pointer */
		c = &opp->deck[i];

		/* Check for correct bluff icon */
		if (c->d_ptr->icons & (ICON_BLUFF_F << g->fight_element))
		{
			/* Count cards with unknown locations */
			if (!c->loc_known) unknown++;
		}

		/* Count bluff cards */
		if (c->bluff) bluff++;
	}

	/* Always call impossible bluffs */
	if (bluff > unknown) return 1;

	/* Clear best path */
	best_path_pos = 0;

	/* Simulate game */
	simulate_game(&sim, g);

	/* XXX Force our turn */
	sim.turn = !sim.turn;
	sim.sim_turn = sim.turn;

	/* Start at beginning of turn */
	sim.p[sim.turn].phase = PHASE_START;

#ifdef DEBUG
	printf("NO CALL BLUFF START\n");
#endif

	/* Get score of not calling */
	score = find_action(&sim);

#ifdef DEBUG
	printf("NO CALL BLUFF END\n");
#endif

	/* Restart simulated game */
	simulate_game(&sim, g);

	/* XXX Force our turn */
	sim.turn = !sim.turn;
	sim.sim_turn = sim.turn;

	/* Start at beginning of turn */
	sim.p[sim.turn].phase = PHASE_START;

	/* Loop over opponent's cards */
	for (i = 1; i < DECK_SIZE; i++)
	{
		/* Get card pointer */
		c = &sim.p[!sim.turn].deck[i];

		/* Skip non-bluff cards */
		if (!c->bluff) continue;

		/* Discard bluff */
		reveal_bluff(&sim, !sim.turn, c->d_ptr);

		/* Mark card as fake */
		c->random_fake = 1;
	}

	/* Give opponent dragon */
	attract_dragon(&sim, !sim.turn);

#ifdef DEBUG
	printf("CALLED BLUFF START\n");
#endif

	/* Check for better options than before */
	if (find_action(&sim) >= score) return 1;

#ifdef DEBUG
	printf("CALLED BLUFF END\n");
#endif

	/* Do not call bluff */
	return 0;
}
コード例 #30
0
ファイル: ai.c プロジェクト: despley/BlueMoonMac
/*
 * Have the AI player take an action.
 */
static void ai_take_action(game *g)
{
	game sim;
	player *p;
	action current;
	int old_turn;

	/* Get player pointer */
	p = &g->p[g->turn];

	/* Save current turn */
	old_turn = g->turn;

	/* Clear best path */
	best_path_pos = 0;
	best_path_score = -1;

	/* Check for beginning of turn */
	if (p->phase == PHASE_START)
	{
		/* Train networks with past inputs */
		perform_training(g, g->turn, NULL);
		perform_training(g, !g->turn, NULL);
	}

	/* Clear random event flag */
	g->random_event = 0;

	/* Check for error in handling choice nodes */
	if (node_len > 0 || node_pos > 0)
	{
		printf("Choice nodes around\n");
	}

	/* Simulate game */
	simulate_game(&sim, g);

#ifdef DEBUG
	printf("START\n");
#endif

	/* Find best action path */
	find_action(&sim);

#ifdef DEBUG
	printf("END\n");
#endif

	/* Start at beginning of path */
	best_path_pos = 0;

	/* Loop until end */
	while (1)
	{
		/* Get current action */
		current = best_path[best_path_pos];

		/* Check for error */
		if (current.act == ACT_CHOOSE)
		{
			printf("Trying to perform choose action!\n");
			break;
		}

		/* Advance to next */
		best_path_pos++;

		/* Perform current action */
		perform_act(g, current);

		/* Check for random event */
		if (g->random_event) break;

		/* Check for retreat */
		if (current.act == ACT_RETREAT) break;

		/* Check for turn change */
		if (g->turn != old_turn) break;

		/* Check for game over */
		if (g->game_over) break;
	}
}