// ---------------------------------------------------------
// CIMOpenAPIExampleContainer::OfferKeyEventL
// ---------------------------------------------------------
//
TKeyResponse CIMOpenAPIExampleContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
	{
	
	// if it's not an event key we're not interested so return not consumed
	if (aType != EEventKey)
		return EKeyWasNotConsumed;
	
	TInt code = aKeyEvent.iCode;

    if ( iGamesGrid && ( !iGamesGrid->IsDimmed() ) ) //&& iGamesGrid->IsFocused()) 
        {
        if ( code == EKeyOK)
            {
            PlayMove();
            return( EKeyWasConsumed );
            }
		else
		    {
   			TKeyResponse returnValue = iGamesGrid->OfferKeyEventL( aKeyEvent, aType );
   		    DrawNow();
   		    return returnValue;
    	    }
        }
        
	return EKeyWasNotConsumed;
	}
Ejemplo n.º 2
0
void DfpnSolver::LookupChildDataNonConst(SgMove move, DfpnData& data)
{
    PlayMove(move);
    if (! TTRead(data))
    {
        data.m_bounds.phi = 1;
        data.m_bounds.delta = 1;
        data.m_work = 0;
    }
    UndoMove();
}
Ejemplo n.º 3
0
void MainMenu()
{
  func = -1;

  while (!stop_button())
    {
    funcLast = func;
    func = ScaleKnob(1, 27);

    if (FDispMenu(1, "Calibrate Lookdown")) CalibrateLookdown();
    if (FDispMenu(2, "Compete!")) Compete();
    if (FDispMenu(3, "Placebo")) Placebo();
    if (FDispMenu(4, "Dance!")) Chop(10);
    if (FDispMenu(5, "Calibrate Soft")) CalibrateSoft();
    if (FDispMenu(6, "Calibrate Hard")) CalibrateHard();
    if (FDispMenu(7, "Speed Calibration")) CalibrateSpeed();

    if (FDispMenu(8, "Lookdown Test")) LookdownTest();
    if (FDispMenu(9, "Orientation")) Orient();
    if (FDispMenu(10, "Straight 1000")) Move(1000,1000);
    if (FDispMenu(11, "Left 90 Soft")) Soft(90, 1);
    if (FDispMenu(12, "Left 90 Hard")) Hard(90);

    if (FDispMenu(13, "Find Line")) FindLine();
    if (FDispMenu(14, "Line Follow")) LineFollower();

    if (FDispMenu(15, "Record"))
      RecordMove(WSetting("Record move", 0, 9));
    if (FDispMenu(16, "Playback"))
      PlayMove(WSetting("Play move", 0, 9));

    /* hbtest.c functions */

    if (FDispMenu(17, "Servo Test")) ServoTest();
    if (FDispMenu(18, "Calibrate Gate")) CalibrateGate();
    if (FDispMenu(19, "Soft Turn Test")) SoftTest();
    if (FDispMenu(20, "Hard Turn Test")) HardTest();
    if (FDispMenu(21, "Spin Test!")) Spinner();
    if (FDispMenu(22, "Shake Test!")) Shaker();
    if (FDispMenu(23, "Bump Test")) BumpTest();

    if (FDispMenu(24, "Test Motors")) testmotors();
    if (FDispMenu(25, "Test Digitals")) testdigitals();
    if (FDispMenu(26, "Test Analogs")) testanalogs();
    if (FDispMenu(27, "Assert Enable")) AssertEnable();
    }
}
Ejemplo n.º 4
0
void DfpnSolver::GetPVFromHash(PointSequence& pv)
{
    // to do: SgAssertRestore r(state of search in subclass);
    int nuMoves = 0;
    for (;; ++nuMoves) 
    {
        DfpnData data;
        if (  ! TTRead(data)
           || data.m_bestMove == SG_NULLMOVE
           )
            break;
        pv.push_back(data.m_bestMove);
        PlayMove(data.m_bestMove);
    }
    while (--nuMoves >= 0)
    	UndoMove();
}
Ejemplo n.º 5
0
bool DfpnSolver::Validate(DfpnHashTable& hashTable, const SgBlackWhite winner,
                          SgSearchTracer& tracer)
{
    SG_ASSERT_BW(winner);
    DfpnData data;
    if (! TTRead(data))
    {
        PointSequence pv;
        StartSearch(hashTable, pv);
        const bool wasRead = TTRead(data);
        SG_DEBUG_ONLY(wasRead);
        SG_ASSERT(wasRead);
    }

    const bool orNode = (winner == GetColorToMove());
    if (orNode)
    {
        if (! data.m_bounds.IsWinning())
        {
            SgWarning() << "OR not winning. DfpnData:" << data << std::endl;
            return false;
        }
    }
    else // AND node
    {
        if (! data.m_bounds.IsLosing())
        {
            SgWarning() << "AND not losing. DfpnData:" << data << std::endl;
            return false;
        }
	}

    SgEmptyBlackWhite currentWinner;
    if (TerminalState(GetColorToMove(), currentWinner))
    {
        if (winner == currentWinner)
            return true;
        else
        {
            SgWarning() << "winner disagreement: " 
                << SgEBW(winner) << ' ' << SgEBW(currentWinner) 
                << std::endl;
            return false;
        }
    }

    std::vector<SgMove> moves;
    if (orNode)
        moves.push_back(data.m_bestMove);
    else // AND node
        GenerateChildren(moves);

    // recurse
    for (std::vector<SgMove>::const_iterator it = moves.begin();
         it != moves.end(); ++it)
    {
        tracer.AddTraceNode(*it, GetColorToMove());
        PlayMove(*it);
        if (! Validate(hashTable, winner, tracer))
            return false;
        UndoMove();
        tracer.TakeBackTraceNode();
    }
    return true;
}
Ejemplo n.º 6
0
size_t DfpnSolver::MID(const DfpnBounds& maxBounds, DfpnHistory& history)
{
    maxBounds.CheckConsistency();
    SG_ASSERT(maxBounds.phi > 1);
    SG_ASSERT(maxBounds.delta > 1);

    ++m_numMIDcalls;
    size_t prevWork = 0;
    SgEmptyBlackWhite colorToMove = GetColorToMove();

    DfpnData data;
    if (TTRead(data)) 
    {
        prevWork = data.m_work;
        if (! maxBounds.GreaterThan(data.m_bounds))
            // Estimated bounds are larger than we had
            // anticipated. The calling state must have computed
            // the max bounds with out of date information, so just
            // return here without doing anything: the caller will
            // now update to this new info and carry on.
            return 0;
    }
    else
    {
        SgEmptyBlackWhite winner = SG_EMPTY;
        if (TerminalState(colorToMove, winner))
        {
            ++m_numTerminal;
            DfpnBounds terminal;
            if (colorToMove == winner)
                DfpnBounds::SetToWinning(terminal);
            else
            {
                SG_ASSERT(SgOppBW(colorToMove) == winner);
                DfpnBounds::SetToLosing(terminal);
            }
            TTWrite(DfpnData(terminal, SG_NULLMOVE, 1));
            return 1;
        }
    }
    
    ++m_generateMoves;
    DfpnChildren children;
    GenerateChildren(children.Children());

    // Not thread safe: perhaps move into while loop below later...
    std::vector<DfpnData> childrenData(children.Size());
    for (size_t i = 0; i < children.Size(); ++i)
        LookupData(childrenData[i], children, i);
    // Index used for progressive widening
    size_t maxChildIndex = ComputeMaxChildIndex(childrenData);

    SgHashCode currentHash = Hash();
    SgMove bestMove = SG_NULLMOVE;
    DfpnBounds currentBounds;
    size_t localWork = 1;
    do
    {
        UpdateBounds(currentBounds, childrenData, maxChildIndex);
        if (! maxBounds.GreaterThan(currentBounds))
            break;

        // Select most proving child
        std::size_t bestIndex = 999999;
        DfpnBoundType delta2 = DfpnBounds::INFTY;
        SelectChild(bestIndex, delta2, childrenData, maxChildIndex);
        bestMove = children.MoveAt(bestIndex);

        // Compute maximum bound for child
        const DfpnBounds childBounds(childrenData[bestIndex].m_bounds);
        DfpnBounds childMaxBounds;
        childMaxBounds.phi = maxBounds.delta 
            - (currentBounds.delta - childBounds.phi);
        childMaxBounds.delta = delta2 == DfpnBounds::INFTY ? maxBounds.phi :
            std::min(maxBounds.phi,
                     std::max(delta2 + 1, DfpnBoundType(delta2 * (1.0 + m_epsilon))));
        SG_ASSERT(childMaxBounds.GreaterThan(childBounds));
        if (delta2 != DfpnBounds::INFTY)
            m_deltaIncrease.Add(float(childMaxBounds.delta-childBounds.delta));

        // Recurse on best child
        PlayMove(bestMove);
        history.Push(bestMove, currentHash);
        localWork += MID(childMaxBounds, history);
        history.Pop();
        UndoMove();

        // Update bounds for best child
        LookupData(childrenData[bestIndex], children, bestIndex);

        // Compute some stats when find winning move
        if (childrenData[bestIndex].m_bounds.IsLosing())
        {
            m_moveOrderingIndex.Add(float(bestIndex));
            m_moveOrderingPercent.Add(float(bestIndex) 
                                      / (float)childrenData.size());
            m_totalWastedWork += prevWork + localWork
                - childrenData[bestIndex].m_work;
        }
        else if (childrenData[bestIndex].m_bounds.IsWinning())
            maxChildIndex = ComputeMaxChildIndex(childrenData);

    } while (! CheckAbort());

    // Find the most delaying move for losing states, and the smallest
    // winning move for winning states.
    if (currentBounds.IsSolved())
    {
        if (currentBounds.IsLosing())
        {
            std::size_t maxWork = 0;
            for (std::size_t i = 0; i < children.Size(); ++i)
            {
                if (childrenData[i].m_work > maxWork)
                {
                    maxWork = childrenData[i].m_work;
                    bestMove = children.MoveAt(i);
                }
            }
        }
        else
        {
            std::size_t minWork = DfpnBounds::INFTY;
            for (std::size_t i = 0; i < children.Size(); ++i)
            {
                if (childrenData[i].m_bounds.IsLosing() 
                    && childrenData[i].m_work < minWork)
                {
                    minWork = childrenData[i].m_work;
                    bestMove = children.MoveAt(i);
                }
            }
        }
    }
    
    // Store search results
    TTWrite(DfpnData(currentBounds, bestMove, localWork + prevWork));
    return localWork;
}
Ejemplo n.º 7
0
void isdf07Mission::Execute(void) {

	
/* The following is needed for editing cineractives. */	
	if (BeginCin == true) {
		BeginCin = PlayMove();
	}

	if (BeginSeq == true) {
		char temp[20] = "***";
		BeginSeq = PlayMovie(temp);
	}
	if (IFace_GetFloat("script.cin.edit") == 1.0) {
//		cinToolSetup();
		IFace_SetFloat("script.cin.edit", 0.0);
	}
/* The above is needed for editing cineractives. */



	
	player = GetPlayerHandle();

	//This section evaluates what has happened.
	checkWing(shabayev, player); //Did we hurt our friendly instructor.
	switch (missionState) {
		case 0: //This will do the setup for the mission.
			spawn1 = GetHandle("spawn_1");
			spawn2 = GetHandle("spawn_2");
			spawn3 = GetHandle("spawn_3");
			creature1=BuildObject("mcjak01",0,"creature1");
			creature2=BuildObject("mcjak01",0,"creature2");
			creature3=BuildObject("mcjak01",0,"creature3");
			creature4=BuildObject("mcjak01",0,"creature4");

			shabayev = BuildObject("ivtank",3,"spawn_shab");
			recy = GetHandle("recycler");
			ruins = GetHandle("ruins");
			SetScrap(1, 40);
//			playerEnemy1 = BuildObject("fvtank", 2, spawn3);
//			Attack(playerEnemy1, player, 1);
			CommandShab();
			AudioMessage("isdf0701.wav");
			AudioMessage("isdf0740.wav");
			AudioMessage("isdf0702.wav");
			AudioMessage("isdf0703.wav");
			SetSkill(shabayev,3);
			SendEnemies(0,player);
			{
				// brad added
				int poolHandle = GetHandle(288);
				SpawnBirds(1, 5, "mcwing01", 0, poolHandle, poolHandle);
			}
			missionState++;
			break;
		case 1: //Check to see if the player has deployed their recycler.
			if (!getNewOrder) {
				ClearObjectives();
				AudioMessage("isdf0704.wav");
				AddObjective("isdf0701.otf", WHITE);
				reminderTimer = (GetTime() + 60.0f);
				if (!IsAlive(animal1)) {
					animal1 = BuildObject("mcjak01", 2, spawn3); //This will be changed to the animal
					Goto(animal1, recy);
					SetIndependence(animal1, 0);
				}
				getNewOrder = true;
			}

			//	recyDeployed = IsDeployed(recy);
			if (recyDeployed) {
				AudioMessage("isdf0706.wav");
				missionState++;
				getNewOrder = false;
			}
			if ((IsAlive(playerEnemy1)) && (!enemy1deployed) &&
				(GetDistance(recy,playerEnemy1)<100.0f))
			{
				enemy1deployed=true;
			}
			if ((!IsAlive(playerEnemy1)) && (!IsAlive(enemy1))) {
				playerEnemy1 = BuildObject("fvtank", comp_team, spawn3);
				Attack(playerEnemy1, player, 1);
			}
			break;
		case 2: //Check to see if the player has built a scavenger.
			if (!getNewOrder) {
				ClearObjectives();
				AddObjective("isdf0702.otf", WHITE);
				reminderTimer = (GetTime() + 60.0f);
				AudioMessage("isdf0708.wav");
				getNewOrder = true;
			}
			if (scavBuilt) {
				AudioMessage("isdf0707.wav");
				reminderTimer = (GetTime() + 30.0f);
				missionState++;
				getNewOrder = false;
			}
			if ((IsAlive(playerEnemy1)) && (!enemy1deployed) &&
				(GetDistance(recy,playerEnemy1)<100.0f))
			{
				enemy1deployed=true;
			}
			if ((!IsAlive(playerEnemy1)) && (!IsAlive(enemy1))) {
				playerEnemy1 = BuildObject("fvtank", 2, spawn3);
				Attack(playerEnemy1, player, 1);
			}

			break;
		case 3: //Check to see if the player has built a construction rig.
			if (!getNewOrder) {
				ClearObjectives();
				AddObjective("isdf0703.otf", WHITE);
				AudioMessage("isdf0710.wav");
				reminderTimer = (GetTime() + 60.0f);
				getNewOrder = true;
			}
			if ((IsAlive(playerEnemy1)) && (!enemy1deployed) &&
				(GetDistance(recy,playerEnemy1)<100.0f))
			{
				enemy1deployed=true;
			}
			if (constBuilt) {
				missionState++;
				getNewOrder = false;
			}
			break;
		case 4: //Check to see if the player has built a power plant.
			if (!getNewOrder) {
				ClearObjectives();
				AddObjective("isdf0704.otf", WHITE);
				AudioMessage("isdf0714.wav");
				reminderTimer = (GetTime() + 60.0f);
				getNewOrder = true;
			}
			if (powerBuilt) {
				missionState++;
				getNewOrder = false;
			}
			if ((!IsAlive(playerEnemy1)) && (!IsAlive(enemy1))) {
				playerEnemy1 = BuildObject("fvtank", 2, spawn3);
				Attack(playerEnemy1, player, 1);

			}

			break;
		case 5:  // check to see if the player has built a relay bunker
			if (!getNewOrder) {
				ClearObjectives();
				AddObjective("isdf0705.otf", WHITE);
				AudioMessage("isdf0716.wav");
				reminderTimer = (GetTime() + 60.0f);
				getNewOrder = true;
			}
			if (relayBuilt) {
				missionState++;
				getNewOrder = false;
			}

			break;
		case 6: //Check to see if the player has built a gun tower
			if (!getNewOrder) {
				ClearObjectives();
				AddObjective("isdf0706.otf", WHITE);
				AudioMessage("isdf0719.wav");
				reminderTimer = (GetTime() + 60.0f);
				getNewOrder = true;
			}
			if (gunTowBuilt) 
			{
				missionState++;
				artil=BuildObject("fvartl",2,"artil");
				Goto(artil,"artillery");
				Handle temp=BuildObject("fvscout",2,spawn2);
				Follow(temp,artil);
				BuildObject("fvscout",2,spawn3);
				Follow(temp,artil);
				artil_counter=0;
				getNewOrder = false;
			}
			break;
		case 7:  // now they will use artillery
			artil_counter++;
			if (artil_counter==300)
			{
				Attack(artil,gtow);
		//		CameraReady();
			}
			if ((artil_counter>300) & (artil_counter<355))
			{
		//		CameraObject(artil,12,8,3,artil);
			}
			if (artil_counter==355)
			{
		//		CameraFinish();
				missionState++;
			}
			// cheesy code but I am tired
			break;
		case 8:
			if (!IsAlive(artil))
			{
				missionState++;
			}
			break;
	
	}
	float currentTime = GetTime();
	if ((reminderTimer < currentTime) && (getNewOrder)) { //This checks to see if we should remind the player of his order.
		getNewOrder = false;
	}
	harrass_count++;
	if (harrass_count%701==0)
	{
		SendEnemies(1,player);
	}
	CommandShab();
	handlePlayerMistakes();
	if (shabState<3) {
		if ((!IsAlive(shabayev) && (!shab_dead)))	
		{
			AudioMessage("isdf0732.wav");
			ClearObjectives();
			AddObjective("isdf05l1.otf",RED,15.0f);
			FailMission(GetTime()+5.0f,"isdf05l1.otf");
			shab_dead=true;
		}
	}

	if ((!IsAround(recy)) && (!shab_dead))
	{
		FailMission(GetTime()+5.0f,"isdf05l1.otf");
		shab_dead=true;
	}


}