示例#1
0
CPlayer::TCheatcode CPlayer::Update(COsGame& game, int flags, CSGMoveListItem& mli) {
   TCheatcode cheatcode;

   // time the call to GetMove()
   i8 ticksPerSecond=GetTicksPerSecond();
   i8 start=GetTicks();

   cheatcode = GetMove(game, flags, mli);

   i8 end=GetTicks();
   mli.tElapsed = (end-start)/(double)ticksPerSecond;

   return cheatcode;
}
示例#2
0
OSErr GridWindMover_c::get_move(int n, Seconds model_time, Seconds step_len, WorldPoint3D* ref, WorldPoint3D* delta, double* windages, short* LE_status, LEType spillType, long spill_ID) {

	if(!ref || !delta || !windages) {
		//cout << "worldpoints array not provided! returning.\n";
		return 1;
	}
	
	// For LEType spillType, check to make sure it is within the valid values
	if( spillType < FORECAST_LE || spillType > UNCERTAINTY_LE)
	{
		// cout << "Invalid spillType.\n";
		return 2;
	}
	
	LERec* prec;
	LERec rec;
	prec = &rec;
	
	WorldPoint3D zero_delta ={0,0,0.};
	
	for (int i = 0; i < n; i++) {
		
		// only operate on LE if the status is in water
		if( LE_status[i] != OILSTAT_INWATER)
		{
			delta[i] = zero_delta;
			continue;
		}
		rec.p = ref[i].p;
		rec.z = ref[i].z;
		rec.windage = windages[i];	// define the windage for the current LE
		
		// let's do the multiply by 1000000 here - this is what gnome expects
		rec.p.pLat *= 1000000;	
		rec.p.pLong*= 1000000;
		
		delta[i] = GetMove(model_time, step_len, spill_ID, i, prec, spillType);
		
		delta[i].p.pLat /= 1000000;
		delta[i].p.pLong /= 1000000;
	}
	
	return noErr;
}
示例#3
0
OSErr ComponentMover_c::get_move(int n, Seconds model_time, Seconds step_len,
							WorldPoint3D *ref, WorldPoint3D *delta, short *LE_status,
							LEType spillType, long spill_ID)
{
	if(!delta || !ref) {
		return 1;
	}
	
	// For LEType spillType, check to make sure it is within the valid values
	if (spillType < FORECAST_LE ||
		spillType > UNCERTAINTY_LE)
	{
		return 2;
	}
	
	LERec* prec;
	LERec rec;
	prec = &rec;
	
	WorldPoint3D zero_delta = { {0, 0}, 0.};
	
	for (int i = 0; i < n; i++) {
		if ( LE_status[i] != OILSTAT_INWATER) {
			delta[i] = zero_delta;
			continue;
		}
		
		rec.p = ref[i].p;
		rec.z = ref[i].z;
		
		// let's do the multiply by 1000000 here - this is what gnome expects
		rec.p.pLat *= 1e6;
		rec.p.pLong *= 1e6;
		
		delta[i] = GetMove(model_time, step_len, spill_ID, i, prec, spillType);
		
		delta[i].p.pLat /= 1e6;
		delta[i].p.pLong /= 1e6;
	}
	
	return noErr;
}
示例#4
0
文件: main.cpp 项目: JustinMorritt/C-
int main()
{
	Board b;

	int choice;
	do
	{
		b.Draw(std::cout);
		choice = askForInt("1: Move Piece\n0: Quit:", 1, 0);
		if(choice == 1)
		{
			std::pair<unsigned, unsigned> move = GetMove(b);
			b.Move(move);

		}

	}while(choice != 0);
	std::cin.get();
	return 0;
}
示例#5
0
// === CODE ===
int main(int argc, char *argv[])
{
	setbuf(stdin, NULL);
	setbuf(stdout, NULL);

	// $X $Y $DIRECTION [$MULTIPLIER=1] $OUTCOME
	CompileRegex(&gRegex_move, "([0-9]+) ([0-9]+) ([A-Z]+)( [0-9]+)? (.*)", REG_EXTENDED);
	// (KILLS|DIES|BOTHDIE) $ATTACKER_RANK $DEFENDER_RANK
	CompileRegex(&gRegex_res, "([A-Z_]+) (.) (.)", REG_EXTENDED);

	{
		 int	colour_id;
		char	colour[6];
		char	opponent[128];
		fscanf(stdin, "%s %s %i %i", colour, opponent, &giBoardWidth, &giBoardHeight);

		if( strcmp(colour, "RED") == 0 )
			colour_id = COLOUR_RED;
		else if( strcmp(colour, "BLUE") == 0 )
			colour_id = COLOUR_BLUE;
		else {
			fprintf(stderr, "Oops... nutty manager, colour = %s\n", colour);
			colour_id = COLOUR_RED;
		}

		DEBUG("colour=%i, opponent='%s', dims = %ix%i", colour_id, opponent, giBoardWidth, giBoardHeight);

		AI_Initialise(colour_id, opponent);
	}
	
	gaBoardState = malloc(giBoardWidth*giBoardHeight);

	for( ;; )
	{
		tMove	mymove, opponent_move;
		char	line[32];

//		DEBUG("Waiting for move");
		ASSERT( fgets(line, sizeof(line), stdin) != NULL );
//		DEBUG("pm line = '%s'", line);

		if( strcmp(line, "\n") == 0 )
			continue ;

		if( strcmp(line, "START\n") == 0 )
		{
//			DEBUG("New game");
			ReadBoardState(stdin, gaBoardState);
			// TODO: Check if this hasn't happened before
			opponent_move.x = 0;
			opponent_move.y = 0;
			opponent_move.dist = 0;
			opponent_move.dir = 0;
		}
		else if( strncmp(line, "QUIT", 4) == 0 )
		{
			// TODO: Result?
			break ;
		}
		else if( strcmp(line, "VICTORY_FLAG\n") == 0 )
		{
			// I win!
			break;
		}
		else
		{
//			DEBUG("GetMove");
			GetMove(line, &opponent_move);
//			DEBUG("Read board state");
			ReadBoardState(stdin, gaBoardState);
		}
		DEBUG("Opposing move %i,%i dir %i dist %i",
			opponent_move.x, opponent_move.y, opponent_move.dir, opponent_move.dist);

		// Silly opponent, you lost
		if( opponent_move.result == RESULT_VICTORY )
			break;

		// Determine move
		AI_HandleMove(0, &opponent_move);
		AI_DoMove(&mymove);
		DEBUG("Chose move %i,%i %i %i", mymove.x, mymove.y, mymove.dir, mymove.dist);
		printf("%i %i %s %i\n", mymove.x, mymove.y, DIR_NAMES[mymove.dir], mymove.dist);

		// Get result of the move
		ASSERT( fgets(line, sizeof(line), stdin) != NULL );
//		DEBUG("res line = '%s'", line);
//
		GetMove(line, &mymove);
		AI_HandleMove(1, &mymove);

		// I WON!
		if( mymove.result == RESULT_VICTORY )
			break;

//		DEBUG("Move over");
	}

	return 0;
}
示例#6
0
int
main(int argc, char **argv)
{
    int NTiles, FromCol, ToCol;

    setlocale(LC_ALL, "");

    switch (argc) {
    case 1:
	NTiles = DEFAULTTILES;
	break;
    case 2:
	NTiles = atoi(argv[1]);
	if (NTiles > MAXTILES || NTiles < MINTILES) {
	    fprintf(stderr, "Range %d to %d\n", MINTILES, MAXTILES);
	    ExitProgram(EXIT_FAILURE);
	}
	break;
    case 3:
	if (strcmp(argv[2], "a")) {
	    Usage();
	    ExitProgram(EXIT_FAILURE);
	}
	NTiles = atoi(argv[1]);
	if (NTiles > MAXTILES || NTiles < MINTILES) {
	    fprintf(stderr, "Range %d to %d\n", MINTILES, MAXTILES);
	    ExitProgram(EXIT_FAILURE);
	}
	AutoFlag = TRUE;
	break;
    default:
	Usage();
	ExitProgram(EXIT_FAILURE);
    }
#ifdef TRACE
    trace(TRACE_MAXIMUM);
#endif
    initscr();
    if (has_colors()) {
	int i;
	short bg = COLOR_BLACK;
	start_color();
#if HAVE_USE_DEFAULT_COLORS
	if (use_default_colors() == OK)
	    bg = -1;
#endif
	for (i = 0; i < 9; i++)
	    init_pair((short) (i + 1), bg, TileColour[i]);
    }
    cbreak();
    if (LINES < 24) {
	endwin();
	fprintf(stderr, "Min screen length 24 lines\n");
	ExitProgram(EXIT_FAILURE);
    }
    if (AutoFlag) {
	curs_set(0);
	leaveok(stdscr, TRUE);	/* Attempt to remove cursor */
    }
    InitTiles(NTiles);
    DisplayTiles();
    if (AutoFlag) {
	do {
	    noecho();
	    AutoMove(0, 2, NTiles);
	} while (!Solved(NTiles));
	sleep(2);
    } else {
	echo();
	for (;;) {
	    if (GetMove(&FromCol, &ToCol))
		break;
	    if (InvalidMove(FromCol, ToCol)) {
		MvAddStr(STATUSLINE, 0, "Invalid Move !!");
		refresh();
		beep();
		continue;
	    }
	    MakeMove(FromCol, ToCol);
	    if (Solved(NTiles)) {
		MvPrintw(STATUSLINE, 0,
			 "Well Done !! You did it in %d moves", NMoves);
		refresh();
		sleep(5);
		break;
	    }
	}
    }
    endwin();
    ExitProgram(EXIT_SUCCESS);
}
示例#7
0
int
main(int argc, char **argv)
{
int NTiles, FromCol, ToCol;
unsigned char AutoFlag = 0;

	switch(argc) {
	case 1:
		NTiles = DEFAULTTILES;
		break;
	case 2:
		NTiles = atoi(argv[1]);
		if (NTiles > MAXTILES || NTiles < MINTILES) {
			fprintf(stderr, "Range %d to %d\n", MINTILES, MAXTILES);
			exit(1);
		}
		break;
	case 3:
		if (strcmp(argv[2], "a")) {
			Usage();
			exit(1);
		}
		NTiles = atoi(argv[1]);
		if (NTiles > MAXTILES || NTiles < MINTILES) {
			fprintf(stderr, "Range %d to %d\n", MINTILES, MAXTILES);
			exit(1);
		}
		AutoFlag = TRUE;
		break;
	default:
		Usage();
		exit(1);
	}
#ifdef NCURSES_VERSION
	trace(TRACE_MAXIMUM);
#endif
	initscr();
	if (!has_colors()) {
		endwin();
		puts("terminal doesn't support color.");
		exit(1);
	}
	start_color();
	{
	int i;
	for (i = 0; i < 9; i++)
		init_pair(i+1, COLOR_BLACK, TileColour[i]);
	}
	cbreak();
	if (LINES < 24) {
		endwin();
		fprintf(stderr, "Min screen length 24 lines\n");
		exit(1);
	}
	if(AutoFlag)
		leaveok(stdscr, TRUE);	/* Attempt to remove cursor */
	InitTiles(NTiles);
	DisplayTiles();
	if(AutoFlag) {
		do {
			noecho();
			AutoMove(0, 2, NTiles);
		} while(!Solved(NTiles));
		sleep(2);
	} else {
		for(;;) {
			if(GetMove(&FromCol, &ToCol))
				break;
			if(InvalidMove(FromCol, ToCol)) {
				mvaddstr(STATUSLINE, 0, "Invalid Move !!");
				refresh();
				beep();
				continue;
			}
			MakeMove(FromCol, ToCol);
			if(Solved(NTiles)) {
				mvprintw(STATUSLINE, 0, "Well Done !! You did it in %d moves", NMoves);
				refresh();
				sleep(5);
				break;
			}
		}
	}
	curs_set(1);
	endwin();
	exit(0);
}
VOID GameThread(VOID *hpTempPipe)
{
   HPIPE   hpGamePipe;
   BOOL    fQuit=FALSE;
   PPIB    dummy;
   PTIB    ptibThrdInfo;
   ULONG   ulID;
   USHORT  usMsg, usData, GameBoard[DIVISIONS][DIVISIONS], usTotalMoves=0;

   /* save pipe handle in own memory */
   hpGamePipe = *(HPIPE *)hpTempPipe;

   /* get thread ID for use in displaying messages */
   if((BOOL)DosGetInfoBlocks(&ptibThrdInfo, &dummy))
   {
      ulID = 0;
   }

   else
   {
      ulID = ptibThrdInfo->tib_ptib2->tib2_ultid;
   }

   InitBoard(GameBoard);

   /* initialize random number generator */
   srand((unsigned) ulID);

   if(!(BOOL)DosConnectNPipe(hpGamePipe))
   {
      while (!fAppExit &&
             !fQuit &&
             !(BOOL)(Pipe_IO(CLIENT, hpGamePipe, &usMsg, &usData, ulID)) &&
             !fAppExit)
      {
         switch (usMsg)
         {
            case CLIENT_MOVE:
               /* enter move from message */
               *((USHORT *)GameBoard + usData) = CLIENT_NUM;
               usTotalMoves++;

               /* test for win if total moves >= DIVISIONS*2-1 */
               if (usTotalMoves >= DIVISIONS*2-1 &&
                   ((BOOL)(usData=WinTest(GameBoard)) ||
                    usTotalMoves == DIVISIONS*DIVISIONS))
               {
                  /* notify of win or draw, and break (switch) on return */
                  if (!usData)
                  {
                     usData = DIVISIONS*DIVISIONS;
                     usMsg = WIN_DRAW;
                  }

                  else
                  {
                     usMsg = WIN_CLIENT;
                  }

                  if ((BOOL)Pipe_IO(SERVER, hpGamePipe, &usMsg, &usData, ulID))
                  {
                     WinPostMsg(hwndMain, WM_MSG, MPFROMLONG(IDMSG_PIPE_WRITE_FAILED), MPVOID);
                     fQuit = TRUE;
                     break;
                  }

                  /* call InitBoard on win */
                  InitBoard(GameBoard);
                  usTotalMoves = 0;

                  break;  /* switch */
               }

               /* NO BREAK */

            case YOU_FIRST:
               /* get move if there are moves left */
               usData = GetMove(GameBoard, usTotalMoves);
               usTotalMoves++;

               /* test for win if total moves >= DIVISIONS*2-1 */
               if (usTotalMoves >= DIVISIONS*2-1 &&
                   ((BOOL)(usMsg=WinTest(GameBoard)) ||
                    usTotalMoves == DIVISIONS*DIVISIONS))
               {
                  /* write game_won message with winning move */
                  if (!usMsg)
                  {
                     usMsg = WIN_DRAW;
                  }

                  else
                  {
                     usMsg = WIN_SERVER;
                  }

                  if ((BOOL)Pipe_IO(SERVER, hpGamePipe, &usMsg, &usData, ulID))
                  {
                     WinPostMsg(hwndMain, WM_MSG, MPFROMLONG(IDMSG_PIPE_WRITE_FAILED), MPVOID);
                     fQuit = TRUE;
                     break;
                  }

                  /* call InitBoard on win */
                  InitBoard(GameBoard);
                  usTotalMoves = 0;
               }

               /* else */
               else
               {
                  /* write move to client */
                  usMsg = SERVER_MOVE;
                  if ((BOOL)Pipe_IO(SERVER, hpGamePipe, &usMsg, &usData, ulID))
                  {
                     WinPostMsg(hwndMain, WM_MSG, MPFROMLONG(IDMSG_PIPE_WRITE_FAILED), MPVOID);
                     fQuit = TRUE;
                  }
               }
               break;

            case ERROR_MSG:
               /* post the error to message queue */
               WinPostMsg(hwndMain, WM_MSG, MPFROMSHORT(usData), MPVOID);

            case CLIENT_QUIT:
               /* quit while */
               fQuit = TRUE;
         }
      }

      DosDisConnectNPipe(hpGamePipe);
   }

   DosClose(hpGamePipe);
}
void Tree::Update()
{
    //NOTE: chosen_index cannot be 0, because 0 denotes 'no-one here' in the grid
    const int chosen_index {
        1 + m_rnd.GetRandomInt(m_active.size() - 1 - 1)
    };
    assert(IsValid(chosen_index,m_active));
    TreeDataPoint& chosen = m_active[chosen_index];

    //Remove active indidual from old spot
    {
        const int x = chosen.GetXpos();
        const int y = chosen.GetYpos();
        m_grid[x][y] = nullptr;
    }

    //?
    m_richness += m_min_speciation_rate*(chosen.GetProbability());

    //Do the move, also tracks that the lineage did not speciate
    const std::pair<int,int> move{GetMove(m_dispersal_kernel,m_rnd,m_dispersal_distance)};
    chosen.Move(
        move.first,move.second,
        m_min_speciation_rate
    );

    //?
    //assert(IsValid(chosen.GetMpos(),m_nodes));
    chosen.GetNode()->IncreaseBranchLength();

    const int to_x = chosen.GetXpos();
    const int to_y = chosen.GetYpos();
    assert(IsValid(to_x,to_y,m_grid));

    GridType& grid_spot_to{m_grid[to_x][to_y]};

    //If there an individual at the dispersed-to spot?
    if (grid_spot_to == nullptr)
    {
        //Just move the individual
        grid_spot_to = &chosen;
        //Nope, this timestep is done
        return;
    }

    //Remove active indidual from old spot
    //m_grid[from_x][from_y] = nullptr;

    //There is an individual at the dispersed-to-spot

    //Let these two coalesce
    //Create a new node to celebrate this event

    m_nodes.push_back(
        TreeNode(
            chosen.GetNode(),
            grid_spot_to->GetNode()
        )
    );
    TreeNode * const new_node {
        &m_nodes.back()
    };

    chosen.GetNode()->SetParent(new_node);
    grid_spot_to->GetNode()->SetParent(new_node);
    grid_spot_to->SetNode(new_node);

    const double probability{
        chosen.GetProbability()
        + grid_spot_to->GetProbability()
        * (1.0-chosen.GetProbability())
    };

    grid_spot_to->SetProbability(probability);

    //Overwrite chosen by last
    TreeDataPoint& last = m_active.back();
    chosen = last;


    const int last_x = last.GetXpos();
    const int last_y = last.GetYpos();

    assert(IsValid(last_x,last_y,m_grid));
    GridType& last_active_spot = m_grid[last_x][last_y];

    if (last_active_spot == &last)
    {
        last_active_spot = &chosen;
    }
    m_active.pop_back();
}
示例#10
0
文件: haino.c 项目: shixv/test
    int
main(int argc, char **argv)
{
    int NTiles, FromCol, ToCol,opt;
    unsigned char AutoFlag = 0;
    if(argc<2 || argc>3){ Usage();exit(0);}
    while( (opt=getopt(argc,argv,"a:n:h") )!=-1)
        switch (opt)
        {
            case 'n':
                NTiles = atoi(optarg);
                if (NTiles > MAXTILES || NTiles < MINTILES)
                {   fprintf(stderr, "步数从 %d 自 %d之间\n", MINTILES, MAXTILES);
                    return EXIT_FAILURE;
                }
                AutoFlag = FALSE;
                break;
            case 'a':
                NTiles = atoi(optarg);
                if (NTiles > MAXTILES || NTiles < MINTILES)
                {       fprintf(stderr, "步数从 %d 自 %d之间\n", MINTILES, MAXTILES);
                    return EXIT_FAILURE;
                }
                AutoFlag = TRUE;
                break;
            case 'h':
            case '?':
            case ':':
                Usage();
                exit(0);
        }
    initscr();
    if (has_colors())
    {
        int i;
        int bg = COLOR_BLACK;
        start_color();
        if (use_default_colors() == OK)
            bg = -1;
        for (i = 0; i < 9; i++)
            init_pair(i + 1, bg, TileColour[i]);
    }
    cbreak();
    /*LINES和COLS是Curses内部变量,用于存储当前终端的行数和列数*/
    if (LINES < 24 || COLS < 80)          /*标准的终端为24行80列*/
    {
        endwin();
        fprintf(stderr, "当前小于 24x80 \n");
        return EXIT_FAILURE;
    }
    if (AutoFlag)
    {
        curs_set(0);
        leaveok(stdscr, TRUE);
    }
    InitTiles(NTiles);
    DisplayTiles();
    if (AutoFlag) {
        do {
            noecho();
            AutoMove(0, 2, NTiles);
        } while (!Solved(NTiles));
        sleep(2);
    } 
    else {
        echo();
        for (;;) {
            if (GetMove(&FromCol, &ToCol))
                break;
            if (InvalidMove(FromCol, ToCol)) {
                mvaddstr(STATUSLINE, 0, "移 动 无 效 !!");
                refresh();
                beep();
                sleep(2);
                continue;
            }
            MakeMove(FromCol, ToCol);
            if (Solved(NTiles)) {
                mvprintw(STATUSLINE, 0, "恭喜!! 恭喜!! 你用 %d 步赢了", NMoves);
                refresh();
                sleep(5);
                break;
            }
        }
    }
    endwin();
    return EXIT_SUCCESS;
}
示例#11
0
int CInterpreter::GetID( char *id_name )
{
	int		id;

	id = FindSymbol( id_name, m_IDKeywords );

	if ( id == -1 )
		return Error("'%s' : unknown identifier", id_name);

	//FIXME: Function pointers would be awfully nice.. but not inside a class!  Weee!!

	switch (id)
	{
	
	//Affect takes control of an entity

	case ID_AFFECT:
		return GetAffect();
		break;

	//Wait for a specified amount of time

	case ID_WAIT:
		return GetWait();
		break;

	//Generic set call

	case ID_SET:
		return GetSet();
		break;

	case ID_LOOP:
		return GetLoop();
		break;

	case ID_PRINT:
		return GetPrint();
		break;

	case ID_USE:
		return GetUse();
		break;

	case ID_FLUSH:
		return GetFlush();
		break;
		
	case ID_RUN:
		return GetRun();
		break;

	case ID_KILL:
		return GetKill();
		break;

	case ID_REMOVE:
		return GetRemove();
		break;

	case ID_CAMERA:
		return GetCamera();
		break;

	case ID_SOUND:
		return GetSound();
		break;

	case ID_MOVE:
		return GetMove();
		break;

	case ID_ROTATE:
		return GetRotate();
		break;

	case ID_IF:
		return GetIf();
		break;

	case ID_ELSE:
		//return Error("syntax error : else without matching if");
		return GetElse();	//FIXME: Protect this call so that floating else's aren't allowed
		break;

	case ID_GET:
		return Error("syntax error : illegal use of \"get\"");
		break;

	case ID_TAG:
		return Error("syntax error : illegal use of \"tag\"");
		break;

	case ID_TASK:
		return GetTask();
		break;

	case ID_DO:
		return GetDo();
		break;

	case ID_DECLARE:
		return GetDeclare();
		break;

	case ID_FREE:
		return GetFree();
		break;

	case ID_REM:
		GetRem();
		break;

	case ID_DOWAIT:
		GetDoWait();
		break;

	case ID_SIGNAL:
		GetSignal();
		break;

	case ID_WAITSIGNAL:
		GetWaitSignal();
		break;

	case ID_PLAY:
		GetPlay();	//Bad eighties slang joke...  yeah, it's not really funny, I know...
		break;

		//Local variable types
	case TK_FLOAT:
	case TK_INT:
	case TK_STRING:
	case TK_VECTOR:
		GetVariable( id );
		break;

	//Unknown ID

	default:
	case -1:
		return Error("'%s' : unknown identifier", id_name);
		break;
	}

	return true;
}
示例#12
0
文件: chess.c 项目: squimmy/Chess
void TakeTurn(Dudes *Board[8][8])
{
	GetMove(Board);
	NextTurn();
}