#include "defs.h" #undef min #undef max #define TINYSQUARE 4 static Frame adversarycontrolframe; static Panel adversarycontrolpanel; void PanelAdversaryModeProc(), PanelShapeChoiceProc(), PanelWeightProc(); int ShapeChoice = 0; initadversary() { adversarycontrolframe = xv_create(mainframe, FRAME, FRAME_SHOW_LABEL, TRUE, XV_LABEL, "Control for Tetris Adversary - weiser", WIN_CMS_NAME, "TETRIS", 0); adversarycontrolpanel = xv_create(adversarycontrolframe, PANEL, 0); (void) xv_create(adversarycontrolpanel, PANEL_CHOICE, PANEL_LABEL_STRING, "Adversary Mode:", PANEL_CHOICE_STRINGS, "Random", "Manual", "Auto", "Constant", 0, PANEL_NOTIFY_PROC, PanelAdversaryModeProc, 0); /* build the shape choice pictures */ { Pixwin *panelpw; Server_image pr[7]; int shape_no; Server_image choice; setup_colours(adversarycontrolframe); for (shape_no = 0; shape_no < 7; shape_no += 1) { pr[shape_no] = xv_create(XV_NULL, SERVER_IMAGE, XV_WIDTH, TINYSQUARE*8, XV_HEIGHT, TINYSQUARE*4, 0); setup_colours(pr[shape_no]); buildTinyPr(pr[shape_no], shape_no, 0, TINYSQUARE, TINYSQUARE, TINYSQUARE); } choice = xv_create(adversarycontrolpanel, PANEL_CHOICE, PANEL_CHOICE_IMAGES, pr[0], pr[1], pr[2], pr[3], pr[4], pr[5], pr[6], 0, PANEL_FEEDBACK, PANEL_MARKED, PANEL_NOTIFY_PROC, PanelShapeChoiceProc, 0); setup_colours(choice); } window_fit(adversarycontrolpanel); window_fit(adversarycontrolframe); } void PanelAdversaryModeProc(item, value, event) Panel_item item; int value; Event *event; { AdversaryEnabled = value; } AdversaryChoosePiece() { switch (AdversaryEnabled) { case 0: /* random */ { display_shape_no = next_no; display_rot = next_rot; next_no = random() % 7; next_rot = random() % 4; break; } case 1: /* manual */ { display_shape_no = 0; break; } case 2: /* auto */ { display_shape_no = pickWorstMove(); break; } case 3: /* constant */ { display_shape_no = ShapeChoice; next_no = display_shape_no; break; } } /* end of switch */ } void PanelShapeChoiceProc(item, value, event) Panel_item item; int value; Event *event; { ShapeChoice = value; } pickWorstMove() { int shape; struct bestPlay b, selectPlay(); int worstscore = 2000000000; int worstshape = -1; for (shape = 0; shape < 7; shape += 1) { b = selectPlay(0 /* no callback */, 0 /* no client data */, 1 /* truncate eval */, displaygrid, shape, 0); if (b.bestscore < worstscore) { worstscore = b.bestscore; worstshape = shape; } } return worstshape; } void adversary_panel_proc() { xv_set(adversarycontrolframe, WIN_SHOW, TRUE, 0); }