Example #1
0
        public void KeyRatios()
        {
            // for calculation check see : https://docs.google.com/spreadsheets/d/1vYEfSleUjF4It_sB-obzRsosTXHEWrdFbhbHDNlNOCM/edit?usp=sharing
            rt = new Results();

            // get some trades
            List<Trade> fills = new List<Trade>(new Trade[] {
                // go long
                new TradeImpl(sym,p,s), // 100 @ $100
                // increase bet
                new TradeImpl(sym,p+inc,s*2),// 300 @ $100.066666
                // take some profits
                new TradeImpl(sym,p+inc*2,s*-1), // 200 @ 100.0666 (profit = 100 * (100.20 - 100.0666) = 13.34) / maxMIU(= 300*100.06666) = .04% ret
                // go flat (round turn)
                new TradeImpl(sym,p+inc*2,s*-2), // 0 @ 0
                // go short
                new TradeImpl(sym,p,s*-2), // -200 @ 100
                // decrease bet
                new TradeImpl(sym,p,s), // -100 @100
                // exit (round turn)
                new TradeImpl(sym,p+inc,s), // 0 @ 0 (gross profit = -0.10*100 = -$10)
                // do another entry
                new TradeImpl(sym,p,s)
            });

            // compute results
            rt = Results.ResultsFromTradeList(fills, g.d);
            // check ratios
#if DEBUG
            g.d(rt.ToString());
#endif
            Assert.AreEqual(-16.413m,rt.SharpeRatio, "bad sharpe ratio");
            Assert.AreEqual(-26.909m, rt.SortinoRatio, "bad sortino ratio");
        }
 public void GetBullsAndCowsMatchesFourCowsTest()
 {
     GameNumber theNumber = new GameNumber(3, 0, 6, 8);
     PlayerGuess playerGuess = new PlayerGuess(8, 6, 0, 3);
     Result expected = new Result(0, 4);
     Result result = GuessChecker.GetBullsAndCowsMatches(playerGuess, theNumber);
     Assert.AreEqual(expected.ToString(), result.ToString());
 }
 public void GetBullsAndCowsMatchesOneBullTest()
 {
     GameNumber theNumber = new GameNumber(1, 2, 6, 8);
     PlayerGuess playerGuess = new PlayerGuess(4, 2, 9, 3);
     Result expected = new Result(1, 0);
     Result result = GuessChecker.GetBullsAndCowsMatches(playerGuess, theNumber);
     Assert.AreEqual(expected.ToString(), result.ToString());
 }
Example #4
0
    // 점수, 승패를 전달해주세요.
    public void Setup(int[] prevScores, int[] scores, Result result) {
        Debug.Log("GameWinner:" + result.ToString() + "[" + scores[0] + " - " + scores[1] + "]");
        
        m_result = result;

        //득점 표시 설정.
        string[] names = { "Score0", "Score1" };
        for(int i=0; i < names.Length; ++i){
            Transform scoreTransform = transform.FindChild( names[i] );
            Score s = scoreTransform.GetComponent<Score>();
            s.Setup( prevScores[i], scores[i]);
        }

        //승패 연출.
        if(m_result == Result.Win){
            m_winLose = Instantiate(m_winPrefab) as GameObject;
            m_winLose.transform.parent = transform;
        }
        else if(m_result == Result.Lose){
            m_winLose = Instantiate(m_losePrefab) as GameObject;
            m_winLose.transform.parent = transform;
        }

    }
Example #5
0
	public bool AddDefaultOrdered (Result r, Fingerprint fp, IWarningLogger logger) 
	{
	    if (r == null)
		throw new ArgumentNullException ();
	    
	    if (default_ordered_id < 0) {
		logger.Error (2037, "Trying to add a dependency to the default " + 
			      "ordered argument, but no default ordered argument is defined",
			      r.ToString ());
		return true;
	    }
	    
	    return AddNamed (default_ordered_id, r, fp, -1, logger);
	}
Example #6
0
	public bool Add (Result r, Fingerprint fp, IWarningLogger logger) 
	{
	    if (r == null)
		throw new ArgumentNullException ();
	    
	    Type t = r.GetType ();
	    List<int> possible_args = new List<int> ();
	    Type best_match = typeof (Result);
	    
	    for (int i = 0; i < args.Length; i++) {
		Type atype = args[i].Type;
		
		// Cannot add an unnamed arg to an ordered arg
		if ((args[i].Flags & ArgFlags.Ordered) != 0)
		    continue;
		
		// Prune out the egregiously wrong arguments (not even a superclass of the result)
		if (! TypeIs (t, atype))
		    continue;
		
		// Prune out those that have been bettered
		if (! TypeIs (atype, best_match))
		    continue;
		
		// If we've narrowed the type further, we don't want any of the
		// previous vaguer matches.
		if (atype.IsSubclassOf (best_match)) {
		    possible_args.Clear ();
		    best_match = atype;
		}
		     
		possible_args.Add (i);
	    }
	    
	    //Console.WriteLine ("Finished with {0} possible arguments", possible_args.Count);
	    
	    if (possible_args.Count == 1) {
		args[possible_args[0]].AddResult (r, fp, -1);
		return false;
	    }
	    
	    if (possible_args.Count > 0) {
		
		// Several possible choices. Check for a default
		foreach (int aid in possible_args) {
		    if ((args[aid].Flags & ArgFlags.Default) != 0) {
			args[aid].AddResult (r, fp, -1);
			return false;
		    }
		}
		
		// No dice. Ambiguity not tolerated. Ah, computers.
		
		StringBuilder sb = new StringBuilder ();
		sb.AppendFormat ("Ambiguous dependency of type {0} could " +
				 "be one of these arguments:", t);
		foreach (int aid in possible_args)
		    sb.AppendFormat (" {0}", args[aid].Name);
		
		logger.Error (2035, sb.ToString (), r.ToString ());
		return true;
	    }

	    // Maybe this is a composite result, and it has a default?
	    // We recurse here, so we tunnel through the composites
	    // sequentially. It's correct to check at every step, rather
	    // than calling FindCompatible, since we don't know what 
	    // type we're looking for.
	    
	    if (r is CompositeResult) {
		CompositeResult cr = (CompositeResult) r;
		
		if (cr.HasDefault) {
		    // See note above about losing FP info in composite results.
		    // this case happens when we are guessing the arg; te 
		    //logger.Warning (9999, "LOSING FINGERPRINT INFO in AC (2)", r.ToString ());
		    
		    if (Add (cr.Default, null, logger) == false)
			return false;
		    
		    // if that didn't work, continue
		    // and give a warning about the container
		    // Result, not the default.
		}
	    }
	    
	    // Bummer.
	    
	    string s = String.Format ("Dependency {0} of type {1} isn't compatible " +
				      "with any defined arguments.", r, t);
	    logger.Error (2034, s, null);
	    return true;
	}
Example #7
0
		internal void CreateStream(Sound sound, string filePath, Modes mode)
		{
			if (sound != null)
			{
				currentResult = Result.Ok;
				IntPtr soundHandle = new IntPtr();

				try
				{
					currentResult = NativeMethods.FMOD_System_CreateStream(handle, filePath, mode, 0, ref soundHandle);
				}
				catch (System.Runtime.InteropServices.ExternalException)
				{
					currentResult = Result.InvalidParameterError;
				}

				if (currentResult == Result.Ok)
				{					
					sound.Handle = soundHandle;
					sound.SoundSystem = this;
				}
				else throw new ApplicationException("could not create stream: " + currentResult.ToString());
			}
			else throw new ArgumentNullException("sound");
		}
Example #8
0
		internal Sound CreateStream(Sound sound, byte[] data, Modes mode, ref CreateSoundExtendedInfo info)
		{
			if (sound != null)
			{
				currentResult = Result.Ok;
				IntPtr soundHandle = new IntPtr();				

				try
				{
					currentResult = NativeMethods.FMOD_System_CreateStream(handle, data, mode, ref info, ref soundHandle);
				}
				catch (System.Runtime.InteropServices.ExternalException)
				{
					currentResult = Result.InvalidParameterError;
				}
				
				if (currentResult == Result.Ok)
				{					
					sound.Handle = soundHandle;				
					sound.SoundSystem = this;
				}
				else throw new ApplicationException("could not create stream: " + currentResult.ToString());

				return sound;
			}
			else throw new ArgumentNullException("sound");
		}
Example #9
0
 private static void OnMultiplayerHost(Result hostResult, MyMultiplayerBase multiplayer)
 {
     if (hostResult == Result.OK)
     {
         Static.StartServer(multiplayer);
     }
     else
     {
         var notification = new MyHudNotification(MyCommonTexts.MultiplayerErrorStartingServer, 10000, MyFontEnum.Red);
         notification.SetTextFormatArguments(hostResult.ToString());
         MyHud.Notifications.Add(notification);
     }
 }
 /// <summary>
 /// Translates the given result value.
 /// </summary>
 /// <param name="result"></param>
 /// <returns></returns>
 public string Translate(Result result)
 {
     return Translate("!Result." + result.ToString());
 }
Example #11
0
        public void ToString_Always_ShouldReturnMessage()
        {
            // Arrange
            var result = new Result
            {
                Message = "the message"
            };

            // Act
            var toStringResult = result.ToString();

            // Assert
            Assert.AreEqual(result.Message, toStringResult);
        }
Example #12
0
        public static void OnJoinBattle(MyGuiScreenProgress progress, Result joinResult, LobbyEnterInfo enterInfo, MyMultiplayerBase multiplayer)
        {
            MyLog.Default.WriteLine(String.Format("Battle lobby join response: {0}, enter state: {1}", joinResult.ToString(), enterInfo.EnterState));

            bool battleCanBeJoined = multiplayer != null && multiplayer.BattleCanBeJoined;
            if (joinResult == Result.OK && enterInfo.EnterState == LobbyEnterResponseEnum.Success && battleCanBeJoined && multiplayer.GetOwner() != MySteam.UserId)
            {
                // Create session with empty world
                Debug.Assert(MySession.Static == null);

                MySession.CreateWithEmptyWorld(multiplayer);
                MySession.Static.Settings.Battle = true;

                progress.CloseScreen();

                MyLog.Default.WriteLine("Battle lobby joined");

                if (MyPerGameSettings.GUI.BattleLobbyClientScreen != null)
                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateScreen(MyPerGameSettings.GUI.BattleLobbyClientScreen));
                else
                    Debug.Fail("No battle lobby client screen");
            }
            else
            {
                string status = "ServerHasLeft";
                if (joinResult != Result.OK)
                {
                    status = joinResult.ToString();
                }
                else if (enterInfo.EnterState != LobbyEnterResponseEnum.Success)
                {
                    status = enterInfo.EnterState.ToString();
                }
                else if (!battleCanBeJoined)
                {
                    status = "Started battle cannot be joined";
                }

                OnJoinBattleFailed(progress, multiplayer, status);
            }
        }
Example #13
0
        internal void SetResult(int column, int row, Result result)
        {
            IsPlaying = true;
            if (Result.MISSION_COMPLETED == result && TotalShips == 0)
            {
                IsWin = true;
                IsPlaying = false;
                IsHit = true;
                return;
            }

            column--;
            row--;
            TotalFires++;
            if (result == Result.HIT || result == Result.MISSION_COMPLETED)
            {

                TotalShips--;
                IsHit = true;
                if (result == Result.MISSION_COMPLETED)
                    IsPlaying = false;
            }
            else
            {
                IsHit = false;

            }
            Board[column, row] = result.ToString();
        }
 public override void Visit(Result result)
 {
     WriteLine(result.ToString());
 }
Example #15
0
	public bool SetDefault (int aid, Result r, IWarningLogger logger) 
	{
	    if (aid < 0 || aid >= args.Length) {
		string s = String.Format ("Trying to set default {0} of nonexistant " +
					  "argument ID {1}.", r, aid);
		logger.Error (2042, s, r.ToString ());
		return true;
	    }

	    args[aid].SetDefault (r);
	    return false;
	}
Example #16
0
        public static void OnJoin(MyGuiScreenProgress progress, Result joinResult, LobbyEnterInfo enterInfo, MyMultiplayerBase multiplayer)
        {
            // HACK: To hide multiplayer from ME
            //if (!MySandboxGame.Services.SteamService.IsActive || MySandboxGame.Services.SteamService.AppId * 2 == 667900)
            //    return;

            MyLog.Default.WriteLine(String.Format("Lobby join response: {0}, enter state: {1}", joinResult.ToString(), enterInfo.EnterState));

            if (joinResult == Result.OK && enterInfo.EnterState == LobbyEnterResponseEnum.Success && multiplayer.GetOwner() != Sync.MyId)
            {
                DownloadWorld(progress, multiplayer);
            }
            else
            {
                string status = "ServerHasLeft";
                if (joinResult != Result.OK)
                {
                    status = joinResult.ToString();
                }
                else if (enterInfo.EnterState != LobbyEnterResponseEnum.Success)
                {
                    status = enterInfo.EnterState.ToString();
                }

                OnJoinFailed(progress, multiplayer, status);
            }
        }
            void LobbiesCompleted(Result result)
            {
                MySandboxGame.Log.WriteLine("Enumerate worlds, result: " + result.ToString());

                if (result != Result.OK)
                {
                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                            messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                            messageText: new StringBuilder("Cannot enumerate worlds, error code: " + result.ToString())));
                }

                IsCompleted = true;
            }
Example #18
0
        public static void OnJoinBattle(MyGuiScreenProgress progress, Result joinResult, LobbyEnterInfo enterInfo, MyMultiplayerBase multiplayer)
        {
            MyLog.Default.WriteLine(String.Format("Battle lobby join response: {0}, enter state: {1}", joinResult.ToString(), enterInfo.EnterState));

            bool battleCanBeJoined = multiplayer != null && multiplayer.BattleCanBeJoined;
            if (joinResult == Result.OK && enterInfo.EnterState == LobbyEnterResponseEnum.Success && battleCanBeJoined && multiplayer.GetOwner() != Sync.MyId)
            {
                // Create session with empty world
                Debug.Assert(MySession.Static == null);

                MySession.CreateWithEmptyWorld(multiplayer);
                MySession.Static.Settings.Battle = true;

                progress.CloseScreen();

                MyLog.Default.WriteLine("Battle lobby joined");

                if (MyPerGameSettings.GUI.BattleLobbyClientScreen != null)
                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateScreen(MyPerGameSettings.GUI.BattleLobbyClientScreen));
                else
                    Debug.Fail("No battle lobby client screen");
            }
            else
            {
                bool statusFullMessage = true;
                string status = MyTexts.GetString(MyCommonTexts.MultiplayerErrorServerHasLeft);

                if (joinResult != Result.OK)
                {
                    status = joinResult.ToString();
                    statusFullMessage = false;
                }
                else if (enterInfo.EnterState != LobbyEnterResponseEnum.Success)
                {
                    status = enterInfo.EnterState.ToString();
                    statusFullMessage = false;
                }
                else if (!battleCanBeJoined)
                {
                    if (MyFakes.ENABLE_JOIN_STARTED_BATTLE)
                    {
                        status = status = MyTexts.GetString(MyCommonTexts.MultiplayerErrorSessionEnded);
                        statusFullMessage = true;
                    }
                    else
                    {
                        status = "GameStarted";
                        statusFullMessage = false;
                    }
                }

                MyLog.Default.WriteLine("Battle join failed: " + status);

                OnJoinBattleFailed(progress, multiplayer, status, statusFullMessage: statusFullMessage);
            }
        }
Example #19
0
		internal Sound CreateSound(string path)
		{
			if (!string.IsNullOrEmpty(path))
			{
				currentResult = Result.Ok;
				IntPtr soundHandle = new IntPtr();
				Sound sound = null;

				try
				{
					currentResult = NativeMethods.FMOD_System_CreateSound(handle, path, (Modes.Hardware | Modes.Fmod2D | Modes.CreateStream | Modes.OpenOnly | Modes.IgnoreTags), 0, ref soundHandle);
					//currentResult = FMOD_System_CreateSound(handle, driveName, (Mode.Hardware | Mode.Fmod2D | Mode.IgnoreTags), 0, ref soundHandle);
				}
				catch (System.Runtime.InteropServices.ExternalException)
				{
					currentResult = Result.InvalidParameterError;
				}

				if (currentResult == Result.Ok)
				{
					sound = new Sound(this, path);
					sound.Handle = soundHandle;
				}
				else throw new ApplicationException("could not create compact disc sound: " + currentResult.ToString());

				return sound;
			}
			else throw new ArgumentNullException("path");
		}
Example #20
0
        public static void OnJoinScenario(MyGuiScreenProgress progress, Result joinResult, LobbyEnterInfo enterInfo, MyMultiplayerBase multiplayer)
        {
            MyLog.Default.WriteLine(String.Format("Lobby join response: {0}, enter state: {1}", joinResult.ToString(), enterInfo.EnterState));
          
            if (joinResult == Result.OK && enterInfo.EnterState == LobbyEnterResponseEnum.Success && multiplayer.GetOwner() != Sync.MyId)
            {
                // Create session with empty world
                if (MySession.Static != null)
                {
                    MySession.Static.Unload();
                    MySession.Static = null;
                }

                MySession.CreateWithEmptyWorld(multiplayer);

                progress.CloseScreen();

                MyScreenManager.CloseAllScreensNowExcept(null);
                MyLog.Default.WriteLine("Scenario lobby joined");

                if (MyPerGameSettings.GUI.ScenarioLobbyClientScreen != null)
                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateScreen(MyPerGameSettings.GUI.ScenarioLobbyClientScreen));
                else
                    Debug.Fail("No scenario lobby client screen");
            }
            else
            {
                string status = "ServerHasLeft";
                if (joinResult != Result.OK)
                {
                    status = joinResult.ToString();
                }
                else if (enterInfo.EnterState != LobbyEnterResponseEnum.Success)
                {
                    status = enterInfo.EnterState.ToString();
                }

                OnJoinBattleFailed(progress, multiplayer, status);
            }
        }
Example #21
0
		internal Sound CreateStream(string filePath, Modes mode)
		{
			currentResult = Result.Ok;
			IntPtr soundHandle = new IntPtr();
			Sound sound = null;

			try
			{
				currentResult = NativeMethods.FMOD_System_CreateStream(handle, filePath, mode, 0, ref soundHandle);
			}
			catch (System.Runtime.InteropServices.ExternalException)
			{
				currentResult = Result.InvalidParameterError;
			}
			
			if (currentResult == Result.Ok)
			{
				sound = new Sound(this, new Uri(filePath));
				sound.Handle = soundHandle;
				sound.SoundSystem = this;
			}
			else throw new ApplicationException("could not create stream: " + currentResult.ToString());

			return sound;
		}
Example #22
0
 private static string GetMessage(Result result, string language)
 {
     return GetMessage(result.ToString(), language);
 }
 public void ResultToStringTest()
 {
     Result result = new Result(2, 2);
     Assert.AreEqual("Bulls: 2, Cows: 2", result.ToString());
 }
Example #24
0
	bool AddNamed (int aid, Result r, Fingerprint fp, 
		       int index_into_values, IWarningLogger logger) 
	{
	    if (aid < 0 || aid >= args.Length) {
		string s = String.Format ("Trying to add {0} to nonexistant " +
					  "argument ID {1}.", r, aid);
		logger.Error (2042, s, r.ToString ());
		return true;
	    }

	    Result subres = CompositeResult.FindCompatible (r, args[aid].Type);

	    if (subres == null) {
		string err = String.Format ("Argument value should be of type {0}, but " +
					    "its type is {1}", args[aid].Type, r.GetType ());
		logger.Error (2036, err, r.ToString ());
		return true;
	    }

	    if (subres == r)
		args[aid].AddResult (r, fp, index_into_values);
	    else
		// FIXME: the FP is really invalid, right?
		args[aid].AddResult (r, null, index_into_values);

	    return false;
	}
 private static string GetErrorString(bool ioFailure, Result result)
 {
     return ioFailure ? "IO Failure" : result.ToString();
 }
Example #26
0
		protected override void OnActivityResult (int requestCode, Result resultCode, Intent data)
		{
			Console.WriteLine (resultCode.ToString ());
			if (requestCode == 1 && data != null) {
				var text = data.GetStringArrayListExtra (RecognizerIntent.ExtraResults);
				FindViewById<EditText> (Resource.Id.edText).Text += System.Environment.NewLine + text[0];

				//Print the result
				Console.WriteLine (text[0]);
			}
		}