Example #1
0
        private void InputChangeMapIDs(IEnumerable <long> originals)
        {
            var input = new IDInputDialog(originals.First());

            input.ShowDialog(this);
            if (input.Confirmed)
            {
                long firstid;
                if (input.WantsAuto)
                {
                    firstid = GetSafeID();
                }
                else
                {
                    firstid = input.SelectedID;
                }
                var desired_range = Util.CreateRange(firstid, originals.Count());
                var from_to       = originals.OrderBy(x => x).Zip(desired_range.OrderBy(x => x), (x, y) => new KeyValuePair <long, long>(x, y));

                // the map IDs that are currently being used and are not changing (potentially conflicting with the ones we want)
                var taken_ids = ActiveSide.GetTakenIDs().Except(originals);
                var conflicts = taken_ids.Intersect(desired_range);

                var replace_option = MapReplaceOption.ReplaceExisting;
                if (conflicts.Any())
                {
                    var picker = new ReplaceOptionDialog(conflicts.Count());
                    picker.ShowDialog(this);
                    if (picker.Confirmed)
                    {
                        replace_option = picker.SelectedOption;
                    }
                    else
                    {
                        return;
                    }
                }

                // go reverse so that we can change 0->1->2->3 without replacing 1 before we can change it to 2
                if (firstid > originals.First())
                {
                    from_to = from_to.Reverse();
                }

                foreach (var change in from_to.ToList())
                {
                    if (replace_option == MapReplaceOption.ChangeExisting && conflicts.Contains(change.Value))
                    {
                        ActiveSide.ChangeMapID(change.Value, GetSafeID());
                    }
                    else if (replace_option == MapReplaceOption.Skip && conflicts.Contains(change.Value))
                    { /* do nothing */
                    }
                    else
                    {
                        ActiveSide.ChangeMapID(change.Key, change.Value);
                    }
                }
            }
        }
Example #2
0
        private StandardGamePosition(
            [NotNull] PiecePosition piecePosition,
            GameSide activeSide,
            int fullMoveIndex,
            CastlingOptions castlingOptions,
            EnPassantCaptureInfo2?enPassantCaptureInfo,
            int halfMoveCountBy50MoveRule)
            : base(piecePosition, activeSide, fullMoveIndex)
        {
            if (piecePosition is null)
            {
                throw new ArgumentNullException(nameof(piecePosition));
            }

            if (halfMoveCountBy50MoveRule < 0)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(halfMoveCountBy50MoveRule),
                          halfMoveCountBy50MoveRule,
                          @"The value cannot be negative.");
            }

            CastlingOptions           = castlingOptions;
            EnPassantCaptureInfo      = enPassantCaptureInfo;
            HalfMoveCountBy50MoveRule = halfMoveCountBy50MoveRule;

            //// TODO [HarinezumiSama] IMPORTANT: This Zobrist key algorithm is different from the one used in the Polyglot opening book (in the en-passant part)
            ZobristKey = PiecePosition.ZobristKey
                         ^ ZobristHashHelper.GetCastlingHash(CastlingOptions)
                         ^ ZobristHashHelper.GetEnPassantHash(
                EnPassantCaptureInfo,
                PiecePosition[ActiveSide.ToPiece(PieceType.Pawn)])
                         ^ ZobristHashHelper.GetTurnHash(ActiveSide);
        }
Example #3
0
    /// <summary>
    /// Switches between the left and right side
    /// </summary>
    /// <returns></returns>
    IEnumerator SwitchTimer()
    {
        if (GameManager.instance.gameState == GameManager.GameState.InGame)
        {
            //Debug.Log("timer"+Timer);
            yield return new WaitForSeconds(Timer);
            switch (sideActive)
            {
                case ActiveSide.left:
                    sideActive = ActiveSide.right;
                    plAnim.SetTrigger("Normal");
                    prAnim.SetTrigger("Shout");
                    audio.PlayOneShot(plAudioShoutEvent);
                    // Debug.Log("audioEvent: " + plAudioShoutEvent);
                    // Debug.Log("RIGHT");
                    // whichButton.text = "R";
                    allowInput = true;
                    break;
                case ActiveSide.right:
                    sideActive = ActiveSide.left;
                    plAnim.SetTrigger("Shout");
                    prAnim.SetTrigger("Normal");
                    audio.PlayOneShot(prAudioShoutEvent);
                    //Debug.Log("audioEvent: " + prAudioShoutEvent);
                    // Debug.Log("LEFT");
                    // whichButton.text = "L";
                    allowInput = true;
                    break;
            }

            StartCoroutine("SwitchTimer");
        }
    }