Beispiel #1
0
    public void Summon(int playerID, XYPair coords, CreatureController.CreatureType crtype)
    {
        GameObject creatureToSummon;

        switch (crtype)
        {
        case CreatureController.CreatureType.Caster:
            creatureToSummon = Caster;
            break;

        case CreatureController.CreatureType.Imp:
            creatureToSummon = Imp;
            break;

        case CreatureController.CreatureType.Ogre:
            creatureToSummon = Ogre;
            break;

        default:
            return;
        }
        GameObject temp = InstantiateAndDisplay(
            boardTiles[coords.x, coords.y].gameObject,
            creatureToSummon,
            ComputePosition(coords.x, coords.y));
        CreatureController cc = temp.GetComponent <CreatureController>();

        cc.Init(playerID, crtype);
        cc.Board    = this;
        cc.Location = coords;
    }
Beispiel #2
0
    public void HighlightMousePosition()
    {
        Vector3 positionToCheck = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        XYPair  pair            = ComputeXYFromPosition(positionToCheck);

        if (pair.x != highlightedPosition.x || pair.y != highlightedPosition.y)
        {
            SpriteRenderer tileRenderer;
            if (boardTiles[pair.x, pair.y] != null)
            {
                tileRenderer = boardTiles[pair.x, pair.y].GetComponent <SpriteRenderer>();
            }
            else
            {
                return;
            }

            tileRenderer.sprite = GameBoardSpriteBright;
            if (boardTiles[highlightedPosition.x, highlightedPosition.y] != null)
            {
                tileRenderer = boardTiles[highlightedPosition.x, highlightedPosition.y].GetComponent <SpriteRenderer>();
            }
            tileRenderer.sprite = GameBoardSpriteDull;
            highlightedPosition = pair;
        }
    }
Beispiel #3
0
    public XYPair ComputeXYFromPosition(Vector3 pos)
    {
        XYPair pair = new XYPair();


        pair.y = (int)(BOARD_HEIGHT / 2 + ((pos.y - baselineY) / (boardTileHeight * .75f)) + .5f);


        pair.x = (int)(BOARD_WIDTH / 2 + 0.5f + (pos.x - baselineX) / boardTileWidth - 0.5f * pair.y);
        if (pair.x < 0)
        {
            pair.x = 0;
        }
        else if (pair.x >= BOARD_WIDTH)
        {
            pair.x = BOARD_WIDTH - 1;
        }
        if (pair.y < 0)
        {
            pair.y = 0;
        }
        else if (pair.y >= BOARD_HEIGHT)
        {
            pair.y = BOARD_HEIGHT - 1;
        }
        return(pair);
    }
        public BoundingRectResizer(Actor actor, XYPair <int> grabHandleThickness, Point?minSize, Point?maxSize,
                                   Func <Rectangle, Rectangle> adjustRenderRectLambda = null) : base(actor)
        {
            this.boundingRect = RequireComponent <BoundingRect>();
            this.hoverable    = RequireComponent <Hoverable>();

            this.maxSize                = maxSize;
            this.grabHandleThickness    = grabHandleThickness;
            this.adjustRenderRectLambda = adjustRenderRectLambda;

            if (minSize.HasValue)
            {
                this.minSize = minSize.Value;
            }
            else
            {
                // This must be exactly ZERO!
                // If we set the min to (n,n) and then create a rect that's (n-1,n-1) we will crash
                this.minSize = Point.Zero;
            }

            ClampRectMin();
            if (maxSize.HasValue)
            {
                ClampRectMax();
            }

            Resized += OnResizeDefault;
        }
Beispiel #5
0
 //TODO: This is just awful. You need to roll all this into the same logical place instead of spreading it between three classes
 public Vector3 TeleportPlayer(int playerID, XYPair pair)
 {
     if (playerID != currentPlayer)
     {
         return(players[playerID].transform.position);
     }
     playerLocations[playerID] = pair;
     return(ComputePosition(pair.x, pair.y));
 }
Beispiel #6
0
    public Vector3 UpdatePlayerPosition(int playerID, XYPair pair)
    {
        if (playerID >= numPlayers || playerID < 0)
        {
            print("playerID is out of bounds");
        }

        if (playerID != currentPlayer)
        {
            return(players[playerID].transform.position);
        }
        playerLocations[playerID]            = pair;
        players[playerID].transform.position = GetTilesAroundPoint(pair, 2)[6].transform.position;
        //AdvancePlayer ();
        return(players[playerID].transform.position);
    }
Beispiel #7
0
    // Use this for initialization
    void Start()
    {
        baselineX = GameBoardTile.transform.position.x;
        baselineY = GameBoardTile.transform.position.y;

        boardTiles = new BoardTile[BOARD_HEIGHT, BOARD_WIDTH];

        boardTileWidth  = (GameBoardSpriteDull.bounds.max - GameBoardSpriteDull.bounds.min).x;
        boardTileHeight = (GameBoardSpriteDull.bounds.max - GameBoardSpriteDull.bounds.min).y;
        //Create starting tile
        for (int i = 0; i < BOARD_WIDTH; i++)
        {
            for (int j = 0; j < BOARD_HEIGHT; j++)
            {
                GetTile(i, j);
            }
        }
        highlightedPosition   = new XYPair();
        highlightedPosition.x = BOARD_WIDTH / 2;
        highlightedPosition.y = BOARD_HEIGHT / 2;

        blankTile       = (Instantiate(GameBoardTile, new Vector3(1000f, 1000f), Quaternion.identity) as GameObject).GetComponent <BoardTile>();
        players         = new MageController[4];
        playerLocations = new XYPair[4];
        currentPlayer   = 0;
        for (int i = 0; i < numPlayers; i++)
        {
            XYPair playerLocation = GetStartingPosition(i);
            playerLocations[i] = playerLocation;
            print("player " + i + " Location" + "x: " + playerLocation.x + "y: " + playerLocation.y);
            GameObject tempPlayer = Instantiate(Player, ComputePosition(playerLocation.x, playerLocation.y), Quaternion.identity) as GameObject;
            tempPlayer.SetActive(true);
            players[i] = tempPlayer.GetComponent <MageController>();
            if (i == 0)
            {
                players[0].SetPlayerName("Aaron");
            }
            players[i].PlayerID = i;
            players[i].Mana     = 1;
        }
        PlayerInputHandler.GameState = PlayerInputHandler.GameStateType.PLAYING;
    }
Beispiel #8
0
        public static void PadXYPairsWithZeros(ref List <XYPair> driftProfileXYPairList, int numZeros)
        {
            var sortByXValue = (from xyPair in driftProfileXYPairList
                                orderby xyPair.XValue
                                select xyPair).ToList();

            var minXValue = sortByXValue.First().XValue;
            var maxXValue = sortByXValue.Last().XValue;

            for (var i = 1; i <= numZeros; i++)
            {
                var lowDriftTime  = minXValue - i;
                var highDriftTime = maxXValue + i;

                var lowXYPair  = new XYPair(lowDriftTime, 0);
                var highXYPair = new XYPair(highDriftTime, 0);

                driftProfileXYPairList.Insert(0, lowXYPair);
                driftProfileXYPairList.Insert(driftProfileXYPairList.Count, highXYPair);
            }
        }
Beispiel #9
0
        // TODO: Sometimes, a normalized value of 1 is never seen. This happens when the # of points is an even number.
        public static List <XYPair> CreateTheoreticalGaussianPeak(double centerOfPeak, double peakFWHM, int numOfPoints)
        {
            var sigma     = peakFWHM / 2.35482;
            var sixSigma  = 3 * peakFWHM;
            var pointSize = sixSigma / (numOfPoints - 1);

            var startPoint = 0 - (int)Math.Floor((numOfPoints - 1) / 2.0);
            var stopPoint  = 0 + (int)Math.Ceiling((numOfPoints - 1) / 2.0);

            var xyPairList = new List <XYPair>();

            for (var i = startPoint; i <= stopPoint; i++)
            {
                var xValue = centerOfPeak + pointSize * i;
                var yValue = 1 / sigma * ONE_OVER_SQRT_OF_2_PI * Math.Exp(-1 * Math.Pow(xValue - centerOfPeak, 2) / (2 * Math.Pow(sigma, 2)));

                var xyPair = new XYPair(xValue, yValue);
                xyPairList.Add(xyPair);
            }

            return(xyPairList);
        }
Beispiel #10
0
        public static void PadXYPairsWithZeros(ref List <XYPair> driftProfileXYPairList, double globalDriftTimeMinimum, double globalDriftTimeMaximum, int numZeros)
        {
            var lowDriftTime  = globalDriftTimeMinimum - (DRIFT_TIME_SLICE_WIDTH / 1000);
            var highDriftTime = globalDriftTimeMaximum + (DRIFT_TIME_SLICE_WIDTH / 1000);

            var lowXYPair  = new XYPair(lowDriftTime, 0);
            var highXYPair = new XYPair(highDriftTime, 0);

            driftProfileXYPairList.Add(lowXYPair);
            driftProfileXYPairList.Add(highXYPair);

            for (var i = 1; i <= numZeros; i++)
            {
                lowDriftTime  = globalDriftTimeMinimum - (DRIFT_TIME_SLICE_WIDTH * i);
                highDriftTime = globalDriftTimeMaximum + (DRIFT_TIME_SLICE_WIDTH * i);

                lowXYPair  = new XYPair(lowDriftTime, 0);
                highXYPair = new XYPair(highDriftTime, 0);

                driftProfileXYPairList.Insert(0, lowXYPair);
                driftProfileXYPairList.Insert(driftProfileXYPairList.Count, highXYPair);
            }
        }
Beispiel #11
0
    //Returns an XYPair one step in the direction of end, starting from start on the hex grid
    public static XYPair PairAlongDirection(XYPair start, XYPair end)
    {
        XYPair retval = start;

        if (start.x < end.x)
        {
            retval.x = start.x + 1;
        }
        else if (start.x > end.x)
        {
            retval.x = start.x - 1;
        }

        if (start.y < end.y)
        {
            retval.y = start.y + 1;
        }
        else if (start.y > end.y)
        {
            retval.y = end.y - 1;
        }
        return(retval);
    }
Beispiel #12
0
    public BoardTile[] GetTilesAroundPoint(XYPair point, int radius)
    {
        BoardTile[] retval = new BoardTile[((radius + 1) * 3) * (radius) + 1];
        int         i      = 0;

        if (point.y % 2 == 0)
        {
            retval[i++] = GetTile(point.x + 1, point.y + 1);
            retval[i++] = GetTile(point.x + 1, point.y - 1);
        }
        else
        {
            retval[i++] = GetTile(point.x - 1, point.y - 1);
            retval[i++] = GetTile(point.x - 1, point.y + 1);
        }

        retval[i++] = GetTile(point.x - 1, point.y);
        retval[i++] = GetTile(point.x + 1, point.y);

        retval[i++] = GetTile(point.x, point.y - 1);
        retval[i++] = GetTile(point.x, point.y + 1);
        retval[i++] = GetTile(point.x, point.y);
        return(retval);
    }
Beispiel #13
0
        public static IEnumerable <LCIMSMSFeature> FindDriftTimePeaks(Peak driftProfilePeak, LCIMSMSFeature lcimsmsFeature, double averageTOFLength, double framePressure)
        {
            var imsmsFeatureList = lcimsmsFeature.IMSMSFeatureList;

            var sortByScanLCQuery = from imsmsFeature in imsmsFeatureList
                                    orderby imsmsFeature.ScanLC
                                    select imsmsFeature;

            var globalIMSScanMinimum = double.MaxValue;
            var globalIMSScanMaximum = double.MinValue;

            // Grab all of the intensity values for each IMS-MS Feature and find the global minimum and maximum Drift Times
            foreach (var imsmsFeature in sortByScanLCQuery)
            {
                imsmsFeature.GetMinAndMaxIMSScan(out var localIMSScanMinimum, out var localIMSScanMaximum);

                if (localIMSScanMinimum < globalIMSScanMinimum)
                {
                    globalIMSScanMinimum = localIMSScanMinimum;
                }
                if (localIMSScanMaximum > globalIMSScanMaximum)
                {
                    globalIMSScanMaximum = localIMSScanMaximum;
                }
            }

            var smoothedDriftProfilePeak = PeakUtil.KDESmooth(driftProfilePeak, Settings.SmoothingStDev); // TODO: Find a good value. 0.15? Less smooth = more conformations!

            var smoothedDriftProfileInterpolation = PeakUtil.GetLinearInterpolationMethod(smoothedDriftProfilePeak);

            var xyPairList        = new List <XYPair>();
            var peakList          = new List <Peak>();
            var previousIntensity = double.MinValue;
            var movingUp          = true;

            // lcimsmsFeature.GetMinAndMaxScanLC(out var minScanLC, out var maxScanLC);

            var minimumIntensityToConsider = smoothedDriftProfilePeak.GetMaximumYValue() * 0.05;

            //DisplayPeakXYData(smoothedDriftProfilePeak);

            //Console.WriteLine("Global IMS Scan Min = " + globalIMSScanMinimum + "\tGlobal IMS Scan Max = " + globalIMSScanMaximum);

            for (var i = globalIMSScanMinimum; i <= globalIMSScanMaximum; i += 1)
            {
                var imsScan   = i;
                var intensity = smoothedDriftProfileInterpolation.Interpolate(imsScan);

                if (intensity > minimumIntensityToConsider)
                {
                    //Console.WriteLine(imsScan + "\t" + intensity + "\t" + movingUp);

                    if (intensity > previousIntensity)
                    {
                        // End of Peak
                        if (!movingUp && xyPairList.Count > 0)
                        {
                            PadXYPairsWithZeros(ref xyPairList, 2);
                            //xyPairList = PadXYPairsWithZeros(xyPairList, imsScanMinimum, i - DRIFT_TIME_SLICE_WIDTH, 1);
                            var peak = new Peak(xyPairList);

                            if (peak.XYPairList.Count >= 7)
                            {
                                peakList.Add(peak);
                            }

                            // Start over with a new Peak
                            xyPairList.Clear();
                            movingUp = true;
                        }
                    }
                    else
                    {
                        movingUp = false;
                    }

                    var xyPair = new XYPair(imsScan, intensity);
                    xyPairList.Add(xyPair);

                    previousIntensity = intensity;
                }
                else
                {
                    movingUp          = false;
                    previousIntensity = 0;
                }
            }

            // When you get to the end, end the last Peak, but only if it has a non-zero value
            if (xyPairList.Any(xyPair => xyPair.YValue > minimumIntensityToConsider))
            {
                PadXYPairsWithZeros(ref xyPairList, 2);
                //xyPairList = PadXYPairsWithZeros(xyPairList, imsScanMinimum, globalIMSScanMaximum, 1);
                var lastPeak = new Peak(xyPairList);

                if (lastPeak.XYPairList.Count >= 7)
                {
                    peakList.Add(lastPeak);
                }
            }

            // var resolvingPower = GetResolvingPower(lcimsmsFeature.Charge);

            var newLCIMSMSFeatureList = new List <LCIMSMSFeature>();

            foreach (var peak in peakList)
            {
                var repIMSScan = peak.GetQuadraticFit();

                // TODO: Fix this
                //double theoreticalFWHM = driftTime / resolvingPower;
                double theoreticalFWHM = 3;

                peak.GetMinAndMaxXValues(out var minimumXValue, out var maximumXValue);

                const int numPoints = 100;

                var normalDistributionXYPairList = PeakUtil.CreateTheoreticalGaussianPeak(repIMSScan, theoreticalFWHM, numPoints);
                PadXYPairsWithZeros(ref normalDistributionXYPairList, 5);
                var normalDistributionPeak = new Peak(normalDistributionXYPairList);

                var peakInterpolation = PeakUtil.GetLinearInterpolationMethod(peak);

                var fitScore = PeakUtil.CalculatePeakFit(peak, normalDistributionPeak, 0);

                // Create a new LC-IMS-MS Feature
                var newLCIMSMSFeature = new LCIMSMSFeature(lcimsmsFeature.Charge)
                {
                    OriginalIndex   = lcimsmsFeature.OriginalIndex,
                    IMSScore        = (float)fitScore,
                    AbundanceMaxRaw = Math.Round(peak.GetMaximumYValue()),
                    // Using Math.Floor instaed of Math.Round because I used to cast this to an int which is esentially Math.Floor.
                    // The difference is negligible, but OHSU would complain if results were the slightest bit different if the app was re-run on the same dataset.
                    AbundanceSumRaw = Math.Floor(peakInterpolation.Integrate(peak.GetMaximumXValue())),
                    DriftTime       = ConvertIMSScanToDriftTime(repIMSScan, averageTOFLength, framePressure)
                };

                // Create new IMS-MS Features by grabbing MS Features in each LC Scan that are in the defined window of the detected drift time
                foreach (var imsmsFeature in lcimsmsFeature.IMSMSFeatureList)
                {
                    var msFeatures = imsmsFeature.FindMSFeaturesInScanIMSRange(minimumXValue, maximumXValue).ToList();

                    if (!msFeatures.Any())
                    {
                        continue;
                    }

                    var newIMSMSFeature = new IMSMSFeature(imsmsFeature.ScanLC, imsmsFeature.Charge);
                    newIMSMSFeature.AddMSFeatureList(msFeatures);
                    newLCIMSMSFeature.AddIMSMSFeature(newIMSMSFeature);
                }

                if (newLCIMSMSFeature.IMSMSFeatureList.Count > 0)
                {
                    newLCIMSMSFeatureList.Add(newLCIMSMSFeature);

                    /*
                     * // TODO: Find LC Peaks
                     * var sortByScanLC = from imsmsFeature in newLCIMSMSFeature.IMSMSFeatureList
                     *                 orderby imsmsFeature.ScanLC ascending
                     *                 select imsmsFeature;
                     *
                     * Console.WriteLine("*************************************************");
                     * Console.WriteLine("Index = " + index + "\tMass = " + newLCIMSMSFeature.CalculateAverageMass() + "\tDrift = " + driftTime + "\tLC Range = " + sortByScanLC.First().ScanLC + "\t" + sortByScanLC.Last().ScanLC);
                     *
                     * List<XYPair> lcXYPairList = new List<XYPair>();
                     * int scanLC = sortByScanLC.First().ScanLC - 1;
                     *
                     * foreach (IMSMSFeature imsmsFeature in sortByScanLC)
                     * {
                     *  int currentScanLC = imsmsFeature.ScanLC;
                     *
                     *  for (int i = scanLC + 1; i < currentScanLC; i++)
                     *  {
                     *      XYPair zeroValue = new XYPair(i, 0);
                     *      lcXYPairList.Add(zeroValue);
                     *      Console.Write("0\t");
                     *  }
                     *
                     *  XYPair xyPair = new XYPair(currentScanLC, imsmsFeature.GetIntensity());
                     *  lcXYPairList.Add(xyPair);
                     *
                     *  scanLC = currentScanLC;
                     *
                     *  Console.Write(imsmsFeature.GetIntensity() + "\t");
                     * }
                     * Console.WriteLine("");
                     * Console.WriteLine("*************************************************");
                     */
                    // TODO: Calculate LC Score
                }
                else
                {
                    //Console.WriteLine("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ FOUND EMPTY $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
                    // TODO: Figure out why this actually happens. I believe that this SHOULD NOT happen. Below is a hack to return a conformation even if this happens
                    // It actually looks like most of these occurences are due to large gaps in the drift time, which cause a small peak to be found in the gap which has no members.

                    //Console.WriteLine("**********************************************************************");
                    //Console.WriteLine("Detected Drift Time = " + driftTime + "\tLow = " + lowDriftTime + "\tHigh = " + highDriftTime);
                    //lcimsmsFeature.PrintLCAndDriftTimeMap();
                    //Console.WriteLine("**********************************************************************");

                    //Console.WriteLine("===============================================================");
                    //Console.WriteLine("DT = " + driftTime + "\tLow DT = " + lowDriftTime + "\tHigh DT = " + highDriftTime);
                    //Console.WriteLine("Global Min = " + globalDriftTimeMinimum + "\tGlobal Max = " + globalDriftTimeMaximum);
                    //peak.PrintPeakToConsole();
                    //Console.WriteLine("===============================================================");
                }
            }

            // Find the Conformation that has the highest member count and store the value into all conformations of this LC-IMS-MS Feature
            if (newLCIMSMSFeatureList.Count > 0)
            {
                var maxMemberCount = newLCIMSMSFeatureList.Select(feature => feature.GetMemberCount()).Max();

                foreach (var feature in newLCIMSMSFeatureList)
                {
                    feature.MaxMemberCount = maxMemberCount;
                }
            }

            return(newLCIMSMSFeatureList);
        }
Beispiel #14
0
 public BoardTile GetTile(XYPair p)
 {
     return(GetTile(p.x, p.y));
 }
Beispiel #15
0
 public BoardTile GetTileAtPoint(XYPair p)
 {
     return(boardTiles[p.x, p.y]);
 }
Beispiel #16
0
    public Vector3 UpdatePlayerPosition(int playerID, Vector3 p)
    {
        XYPair pair = ComputeXYFromPosition(p);

        return(UpdatePlayerPosition(playerID, pair));
    }