Example #1
0
 public override void OnStateExit()
 {
     _specialCaseForNextRound = new SpecialCaseState(null, NextStatePriority.Default);
     foreach (var pocket in Pockets)
     {
         Pockets.SetPocketHighlightState(pocket, false);
     }
 }
 public void Setup(Puzzle puzzle)
 {
     Current = puzzle;
     CurrentPuzzleStartedUtc = DateTime.UtcNow;
     CurrentPuzzleEndedUtc   = null;
     PossibleVariations      = puzzle.Solutions.Select(x => x.Split(' '));
     FENs.Clear();
     FENs.Add(puzzle.InitialFen);
     Checks.Clear();
     Checks.Add(Current.Game.IsInCheck(Current.Game.WhoseTurn) ? Current.Game.WhoseTurn.ToString().ToLowerInvariant() : null);
     Moves.Clear();
     Moves.Add(null);
     Pockets.Clear();
     Pockets.Add(Current.Game.GenerateJsonPocket());
 }
Example #3
0
        private void UpdateSelectedPocketIndex(int value)
        {
            _selectedPocketIndex = value;
            for (int index = 0; index < buttonText.Length; index++)
            {
                buttonText[index].color = index == value ? selectedPocketTextColor : standardPocketTextColor;
            }

            foreach (var pocket in Pockets)
            {
                Pockets.SetPocketHighlightState(pocket, false);
            }
            Pockets.SetPocketHighlightState(value, true);

            callPocketState.CallPocket(SelectedPocketIndex);
        }
        public void UsersRegisterAsync([FromBody] User user)
        {
            casinodbContext cc = new casinodbContext();

            //Users user = UserHelper.RegisterUserAsync().GetAwaiter().GetResult();
            Console.WriteLine("user reached data register as: " + user.Name + " username: "******"user: "******"with username: "******"is successfully submitted to the database!");
        }
        SubmittedMoveResponse MakeMoveAndDropCommon(SubmittedMoveResponse response, string moveStr)
        {
            response.Check = Current.Game.IsInCheck(Current.Game.WhoseTurn) ? Current.Game.WhoseTurn.ToString().ToLowerInvariant() : null;
            Checks.Add(response.Check);
            string fen = Current.Game.GetFen();

            response.FEN = fen;
            FENs.Add(fen);
            Dictionary <string, int> pocket = Current.Game.GenerateJsonPocket();

            response.Pocket = pocket;
            Pockets.Add(pocket);

            if (Current.Game.IsWinner(ChessUtilities.GetOpponentOf(Current.Game.WhoseTurn)))
            {
                PuzzleFinished(response, true);
                return(response);
            }

            if (!PossibleVariations.Any(x => CompareMoves(x.First(), moveStr) == 0))
            {
                PuzzleFinished(response, false);
                return(response);
            }

            PossibleVariations = PossibleVariations.Where(x => CompareMoves(x.First(), moveStr) == 0).Select(x => x.Skip(1));

            if (PossibleVariations.Any(x => x.Count() == 0))
            {
                PuzzleFinished(response, true);
                return(response);
            }

            string moveToPlay = PossibleVariations.First().First();

            if (!moveToPlay.Contains("@"))
            {
                string[] parts = moveToPlay.Split('-', '=');
                Current.Game.MakeMove(new Move(parts[0], parts[1], Current.Game.WhoseTurn, parts.Length == 2 ? null : new char?(parts[2][0])), true);
            }
            else
            {
                string[] parts = moveToPlay.Split('@');

                CrazyhouseChessGame zhCurrent = Current.Game as CrazyhouseChessGame;
                Piece toDrop = zhCurrent.MapPgnCharToPiece(parts[0] == "" ? 'P' : parts[0][0], zhCurrent.WhoseTurn);
                Drop  drop   = new Drop(toDrop, new Position(parts[1]), zhCurrent.WhoseTurn);
                zhCurrent.ApplyDrop(drop, true);
            }

            response.Play = moveToPlay;
            Moves.Add(moveToPlay);
            response.FenAfterPlay = Current.Game.GetFen();
            FENs.Add(response.FenAfterPlay);
            response.CheckAfterAutoMove = Current.Game.IsInCheck(Current.Game.WhoseTurn) ? Current.Game.WhoseTurn.ToString().ToLowerInvariant() : null;
            Checks.Add(response.CheckAfterAutoMove);
            response.Moves               = Current.Game.GetValidMoves(Current.Game.WhoseTurn);
            response.Correct             = 0;
            response.PocketAfterAutoMove = Current.Game.GenerateJsonPocket();
            Pockets.Add(response.PocketAfterAutoMove);
            PossibleVariations = PossibleVariations.Select(x => x.Skip(1));
            if (PossibleVariations.Any(x => !x.Any()))
            {
                PuzzleFinished(response, true);
            }
            return(response);
        }
        void PuzzleFinished(SubmittedMoveResponse response, bool correct)
        {
            CurrentPuzzleEndedUtc = DateTime.UtcNow;

            response.Correct         = correct ? 1 : -1;
            response.ExplanationSafe = Current.ExplanationSafe;

            if (!PastPuzzleIds.Contains(Current.ID))
            {
                PastPuzzleIds.Add(Current.ID);
            }

            string analysisUrl = "https://lichess.org/analysis/{0}/{1}";
            string analysisUrlVariant;

            switch (Current.Variant)
            {
            case "Atomic":
                analysisUrlVariant = "atomic";
                break;

            case "Antichess":
                analysisUrlVariant = "antichess";
                break;

            case "Crazyhouse":
                analysisUrlVariant = "crazyhouse";
                break;

            case "Horde":
                analysisUrlVariant = "horde";
                break;

            case "KingOfTheHill":
                analysisUrlVariant = "kingOfTheHill";
                break;

            case "ThreeCheck":
                analysisUrlVariant = "threeCheck";
                break;

            case "RacingKings":
                analysisUrlVariant = "racingKings";
                break;

            default:
                analysisUrlVariant = "unknown";
                break;
            }
            response.AnalysisUrl = string.Format(analysisUrl, analysisUrlVariant, Current.InitialFen.Replace(' ', '_'));

            List <string> replayFens   = new List <string>(FENs);
            List <string> replayChecks = new List <string>(Checks);
            List <string> replayMoves  = new List <string>(Moves);
            List <Dictionary <string, int> > replayPockets = new List <Dictionary <string, int> >(Pockets);

            if (!correct)
            {
                Moves.RemoveAt(Moves.Count - 1);
                FENs.RemoveAt(FENs.Count - 1);
                Checks.RemoveAt(Checks.Count - 1);
                Pockets.RemoveAt(Pockets.Count - 1);

                replayFens.RemoveAt(replayFens.Count - 1);
                replayMoves.RemoveAt(replayMoves.Count - 1);
                replayChecks.RemoveAt(replayChecks.Count - 1);
                replayPockets.RemoveAt(replayPockets.Count - 1);

                response.FEN    = FENs[FENs.Count - 1];
                response.Pocket = Pockets[Pockets.Count - 1];

                ChessGame correctGame = gameConstructor.Construct(Current.Variant, Current.InitialFen);
                int       i           = 0;
                var       full        = replayMoves.Concat(PossibleVariations.First());
                foreach (string move in full)
                {
                    if (move == null)
                    {
                        i++; continue;
                    }
                    if (!move.Contains("@"))
                    {
                        string[] p = move.Split('-', '=');
                        correctGame.MakeMove(new Move(p[0], p[1], correctGame.WhoseTurn, p.Length == 2 ? null : new char?(p[2][0])), true);
                    }
                    else
                    {
                        string[] p = move.Split('@');
                        if (string.IsNullOrEmpty(p[0]))
                        {
                            p[0] = "P";
                        }
                        Drop drop = new Drop(correctGame.MapPgnCharToPiece(p[0][0], correctGame.WhoseTurn), new Position(p[1]), correctGame.WhoseTurn);
                        (correctGame as CrazyhouseChessGame).ApplyDrop(drop, true);
                    }
                    if (i >= Moves.Count)
                    {
                        replayFens.Add(correctGame.GetFen());
                        replayChecks.Add(correctGame.IsInCheck(correctGame.WhoseTurn) ? correctGame.WhoseTurn.ToString().ToLowerInvariant() : null);
                        replayMoves.Add(move);
                        replayPockets.Add(correctGame.GenerateJsonPocket());
                    }
                    i++;
                }

                Current.Game   = gameConstructor.Construct(Current.Variant, response.FEN);
                response.Moves = Current.Game.GetValidMoves(Current.Game.WhoseTurn);
                response.Check = Current.Game.IsInCheck(Player.White) ? "white" : (Current.Game.IsInCheck(Player.Black) ? "black" : null);
            }
            response.ReplayFENs    = replayFens;
            response.ReplayChecks  = replayChecks;
            response.ReplayMoves   = replayMoves;
            response.ReplayPockets = replayPockets;
        }
        /// <summary>
        /// The SpinWheel method is called to spin the wheel.
        /// </summary>
        public void SpinWheel()
        {
            try
            {
                if (_wheelStoryBoard == null)
                {
                    // Initialize the story board.
                    _wheelStoryBoard            = new Storyboard();
                    _wheelStoryBoard.Completed += new EventHandler(WheelStopped);
                }
                else if (_wheelStoryBoard.GetCurrentState(_wheelControl) == ClockState.Stopped || _wheelStoryBoard.GetIsPaused(_wheelControl))
                {
                    return; // Wheel is already spinning or is paused - do not spin.
                }

                // Wheel spinning animation 1.
                if (_wheelSpinningAnimation1 == null)
                {
                    // Initialize the animation.
                    _wheelSpinningAnimation1              = new DoubleAnimation();
                    _wheelSpinningAnimation1.SpeedRatio   = Constants.WheelSpeedRatio;
                    _wheelSpinningAnimation1.FillBehavior = FillBehavior.HoldEnd;
                    Storyboard.SetTargetName(_wheelSpinningAnimation1, Constants.WheelRotateTransformName);
                    Storyboard.SetTargetProperty(_wheelSpinningAnimation1, new PropertyPath(RotateTransform.AngleProperty));
                    _wheelStoryBoard.Children.Add(_wheelSpinningAnimation1);  // Add the animation to the story board.
                }
                // Number of rotations in total degrees - multiply by wheel speed ratio (negative degrees for counter clockwise).
                double wheelEndAngleDegrees = -1 * _randomNumberGenerator.Next(Constants.MinimumWheelSpinDistanceDegrees, Constants.MaximumWheelSpinDistanceDegrees);
                _wheelSpinningAnimation1.By = wheelEndAngleDegrees * Constants.WheelSpeedRatio;
                // Duration of spin seconds - multiply by wheel speed ratio.
                double spinDurationSeconds = Constants.WheelSpinDurationSeconds;
                _wheelSpinningAnimation1.Duration = TimeSpan.FromSeconds(spinDurationSeconds * Constants.WheelSpeedRatio);
                _wheelSpinningAnimation1EndTime   = DateTime.Now.AddSeconds(spinDurationSeconds);

                // Wheel spinning animation 2.
                if (_wheelSpinningAnimation2 == null)
                {
                    // Initialize the animation.
                    _wheelSpinningAnimation2                   = new DoubleAnimation();
                    _wheelSpinningAnimation2.SpeedRatio        = Constants.WheelSpeedRatio;
                    _wheelSpinningAnimation2.DecelerationRatio = Constants.StoppingDecelerationRatio;
                    _wheelSpinningAnimation2.FillBehavior      = FillBehavior.HoldEnd;
                    _wheelSpinningAnimation2.By                = -1 * Constants.StoppingSpinDistanceDegrees;
                    _wheelSpinningAnimation2.Duration          = TimeSpan.FromSeconds(spinDurationSeconds * Constants.WheelSpeedRatio);
                    Storyboard.SetTargetName(_wheelSpinningAnimation2, Constants.WheelRotateTransformName);
                    Storyboard.SetTargetProperty(_wheelSpinningAnimation2, new PropertyPath(RotateTransform.AngleProperty));
                    _wheelStoryBoard.Children.Add(_wheelSpinningAnimation2);  // Add the animation to the story board.
                }
                // Begin time - begins after the first wheel spinning animation.
                _wheelSpinningAnimation2.BeginTime = TimeSpan.FromSeconds(spinDurationSeconds);

                // Select a winning number, and retrieve the corresponding winning pocket.
                int number = _randomNumberGenerator.Next(Constants.MinimumWinningNumber, Constants.MaximumWinningNumber);
                _winningNumber = Pockets.SingleOrDefault(x => x.Number == number);
                double winningNumberStartAngleDegrees = _winningNumber.AngularPositionDegrees + ((RotateTransform)_wheelControl.RenderTransform).Angle;
                _winningNumberEndAngleDegrees = CorrectAngleDegrees(winningNumberStartAngleDegrees + (double)_wheelSpinningAnimation1.By);

                _wheelStoryBoard.Begin(_wheelControl, true);    // Start the story board.
                OnWheelSpinning?.Invoke(true);                  // Publish the status of the wheel.
            }
            catch (Exception ex)
            {
                throw new Exception("RouletteWheel.SpinWheel(): " + ex.ToString());
            }
        }
Example #8
0
 public static Bet Rouge(decimal amount)
 {
     return(new Bet(Pockets.Where(p => p.Red).Select(p => p.Number)));
 }
Example #9
0
 public static Bet Impair(decimal amount)
 {
     return(new Bet(Pockets.Where(p => p.Odd).Select(p => p.Number)));
 }
Example #10
0
 public static Bet DerniereDouzaine(decimal amount)
 {
     return(new Bet(Pockets.Where(p => p.LastDozen).Select(p => p.Number)));
 }
Example #11
0
 public static Bet MoyenneDouzaine(decimal amount)
 {
     return(new Bet(Pockets.Where(p => p.MiddleDozen).Select(p => p.Number)));
 }
Example #12
0
 public static Bet Manque(decimal amount)
 {
     return(new Bet(Pockets.Where(p => p.Low).Select(p => p.Number)));
 }
Example #13
0
 public static Bet Passe(decimal amount)
 {
     return(new Bet(Pockets.Where(p => p.High).Select(p => p.Number)));
 }
Example #14
0
 public static Bet Noir(decimal amount)
 {
     return(new Bet(Pockets.Where(p => p.Black).Select(p => p.Number)));
 }
Example #15
0
 public void AddToPockets(GameObject stored_object)
 {
     Pockets.Add(stored_object);
 }