Пример #1
0
        /// <summary>
        ///     检查重复note
        /// </summary>
        /// <param name="defaultScore"></param>
        public void CheckRepeat(DefaultScore defaultScore)
        {
            var repeatList = defaultScore.Notes.GroupBy(p => new { p.Time, p.Track }).Where(p => p.Count() > 1).ToList();

            var str = "位于\r\n";

            foreach (var i in repeatList)
            {
                str += $"Time:{i.Key.Time} Track:{i.Key.Track} NoteCount:{i.Count()}\r\n";
            }

            str += "转换过程不作处理,请在原谱面文件上自行修改";

            if (repeatList.Count != 0)
            {
                MessageBox.Show(str, "检测到重复note");
            }
        }
Пример #2
0
        /// <summary>
        ///     从simulator谱面文本构造谱面对象
        /// </summary>
        /// <param name="scoreString">谱面文本</param>
        public DefaultScore GetDefaultScoreFromBangSimulatorScore(string scoreString)
        {
            var defaultScore     = new DefaultScore();
            var scoreStringArray =
                scoreString.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            if (int.TryParse(scoreStringArray[0], out var delay_ms) && float.TryParse(scoreStringArray[1], out var bpm))
            {
                defaultScore.Delay_ms = delay_ms;
                defaultScore.Bpm      = bpm;
            }
            else
            {
                throw new Exception("转换出错,请检查原谱面文本");
            }

            var notes = new List <Note>();

            for (var i = 3; i < scoreStringArray.Length; i++)
            {
                var str = scoreStringArray[i].Split('/');
                if (double.TryParse(str[0], out var time) && Enum.TryParse(str[1], out NoteType noteType) &&
                    int.TryParse(str[2], out var track))
                {
                    notes.Add(new Note
                    {
                        Time     = time + _delay,
                        NoteType = noteType,
                        Track    = track
                    });
                }
                else
                {
                    throw new Exception("转换出错,请检查原谱面文本");
                }
            }

            //先按时间排,然后按轨道从左到右排
            defaultScore.Notes = notes.OrderBy(p => p.Time).ThenBy(p => p.Track).ToList();
            return(defaultScore);
        }
        public override PlayerTask GetMove(POGame poGame)
        {
            _player = poGame.CurrentPlayer;

            if (_player.MulliganState == Mulligan.INPUT)
            {
                List <int> mulligan = new DefaultScore().MulliganRule().Invoke(_player.Choice.Choices.Select(p => poGame.getGame().IdEntityDic[p]).ToList());
                return(ChooseTask.Mulligan(_player, mulligan));
            }


            Dictionary <KeyValuePair <PlayerTask, POGame>, int> ScoreDict = new Dictionary <KeyValuePair <PlayerTask, POGame>, int>();
            Stopwatch stopwatch = new Stopwatch();

            var simulation = poGame.Simulate(_player.Options()).Where(x => x.Value != null);

            simulation = simulation.OrderBy(x => Score(x.Value, _player.PlayerId));
            stopwatch.Start();

            foreach (var task in simulation)
            {
                if (stopwatch.ElapsedMilliseconds > 25000)
                {
                    break;
                }

                if (task.Key.PlayerTaskType == PlayerTaskType.END_TURN)
                {
                    ScoreDict.Add(task, Score(task.Value, _player.PlayerId));
                    continue;
                }
                POGame gamecopy     = task.Value.getCopy();
                var    options      = gamecopy.CurrentPlayer.Options();
                var    simulationv2 = gamecopy.Simulate(options).Where(x => x.Value != null);
                simulationv2 = simulationv2.OrderBy(x => Score(x.Value, _player.PlayerId));
                Dictionary <KeyValuePair <PlayerTask, POGame>, int> ScoreDict2 = new Dictionary <KeyValuePair <PlayerTask, POGame>, int>();

                foreach (var task2 in simulationv2)
                {
                    if (stopwatch.ElapsedMilliseconds > 25000)
                    {
                        break;
                    }

                    POGame gamecopy2 = task2.Value.getCopy();
                    var    options2  = gamecopy2.CurrentPlayer.Options();
                    if (task2.Key.PlayerTaskType == PlayerTaskType.END_TURN || options2.Count > 20)
                    {
                        ScoreDict2.Add(task2, Score(task2.Value, _player.PlayerId));
                        continue;
                    }
                    var simulationv3 = gamecopy2.Simulate(options2).Where(x => x.Value != null);
                    simulationv3 = simulationv3.OrderBy(x => Score(x.Value, _player.PlayerId));

                    //evaluate the best score out of the third simulation and add it in scoredict 2
                    ScoreDict2.Add(task2, Score(simulationv3.OrderBy(x => Score(x.Value, _player.PlayerId)).Last().Value, _player.PlayerId));
                }
                ScoreDict.Add(task, ScoreDict2.OrderBy(x => x.Value).Last().Value);
            }
            //if(stopwatch.ElapsedMilliseconds>25000)
            //	Console.WriteLine(stopwatch.ElapsedMilliseconds);


            return(simulation.Any() ?
                   ScoreDict.OrderBy(x => x.Value).Last().Key.Key :
                   _player.Options().First(x => x.PlayerTaskType == PlayerTaskType.END_TURN));
        }
Пример #4
0
        /// <summary>
        ///     从bestdori谱面文本构造谱面对象
        /// </summary>
        /// <param name="scoreString">谱面文本</param>
        public DefaultScore GetDefaultScoreFromBestdoriScore(string scoreString)
        {
            var defaultScore = new DefaultScore();
            var arrayList    = JsonConvert.DeserializeObject <ArrayList>(scoreString);
            var head         = new Head
            {
                bpm  = ((JObject)arrayList[0])["bpm"].ToObject <float>(),
                beat = ((JObject)arrayList[0])["beat"].ToObject <double>()
            };

            defaultScore.Bpm      = head.bpm;
            defaultScore.Delay_ms = (int)(head.beat / head.bpm * 60000);

            //提取note列表
            arrayList.RemoveAt(0);
            var tempJson = JsonConvert.SerializeObject(arrayList);
            var tempList = JsonConvert.DeserializeObject <List <DataClass.Bestdori.Note> >(tempJson);

            var notes = new List <Note>();

            foreach (var note in tempList)
            {
                var tempNote = new Note {
                    Time = note.beat + _delay, Track = note.lane
                };

                if (note.note == DataClass.Bestdori.NoteType.Single &&
                    !note.skill &&
                    !note.flick)
                {
                    tempNote.NoteType = NoteType.白键;
                    notes.Add(tempNote);
                    continue;
                }

                if (note.note == DataClass.Bestdori.NoteType.Single &&
                    note.skill &&
                    !note.flick)
                {
                    tempNote.NoteType = NoteType.技能;
                    notes.Add(tempNote);
                    continue;
                }

                if (note.note == DataClass.Bestdori.NoteType.Single &&
                    !note.skill &&
                    note.flick)
                {
                    tempNote.NoteType = NoteType.粉键;
                    notes.Add(tempNote);
                    continue;
                }

                if (note.note == DataClass.Bestdori.NoteType.Slide &&
                    note.pos == PosType.A &&
                    note.start &&
                    !note.end &&
                    !note.flick)
                {
                    tempNote.NoteType = NoteType.滑条a_开始;
                    notes.Add(tempNote);
                    continue;
                }

                if (note.note == DataClass.Bestdori.NoteType.Slide &&
                    note.pos == PosType.A &&
                    !note.start &&
                    !note.end &&
                    !note.flick)
                {
                    tempNote.NoteType = NoteType.滑条a_中间;
                    notes.Add(tempNote);
                    continue;
                }

                if (note.note == DataClass.Bestdori.NoteType.Slide &&
                    note.pos == PosType.A &&
                    !note.start &&
                    note.end &&
                    !note.flick)
                {
                    tempNote.NoteType = NoteType.滑条a_结束;
                    notes.Add(tempNote);
                    continue;
                }

                if (note.note == DataClass.Bestdori.NoteType.Slide &&
                    note.pos == PosType.A &&
                    !note.start &&
                    note.end &&
                    note.flick)
                {
                    tempNote.NoteType = NoteType.滑条a_粉键结束;
                    notes.Add(tempNote);
                    continue;
                }

                if (note.note == DataClass.Bestdori.NoteType.Slide &&
                    note.pos == PosType.B &&
                    note.start &&
                    !note.end &&
                    !note.flick)
                {
                    tempNote.NoteType = NoteType.滑条b_开始;
                    notes.Add(tempNote);
                    continue;
                }

                if (note.note == DataClass.Bestdori.NoteType.Slide &&
                    note.pos == PosType.B &&
                    !note.start &&
                    !note.end &&
                    !note.flick)
                {
                    tempNote.NoteType = NoteType.滑条b_中间;
                    notes.Add(tempNote);
                    continue;
                }

                if (note.note == DataClass.Bestdori.NoteType.Slide &&
                    note.pos == PosType.B &&
                    !note.start &&
                    note.end &&
                    !note.flick)
                {
                    tempNote.NoteType = NoteType.滑条b_结束;
                    notes.Add(tempNote);
                    continue;
                }

                if (note.note == DataClass.Bestdori.NoteType.Slide &&
                    note.pos == PosType.B &&
                    !note.start &&
                    note.end &&
                    note.flick)
                {
                    tempNote.NoteType = NoteType.滑条b_粉键结束;
                    notes.Add(tempNote);
                    continue;
                }

                throw new Exception("bestdori=>bangSimulator音符转换失败");
            }

            //先按时间排,然后按轨道从左到右排
            defaultScore.Notes = notes.OrderBy(p => p.Time).ThenBy(p => p.Track).ToList();
            return(defaultScore);
        }
Пример #5
0
        /// <summary>
        ///		修复首尾连接同类型滑条
        /// </summary>
        /// <param name="defaultScore"></param>
        public void FixSamePosSlide(DefaultScore defaultScore)
        {
            var notes = defaultScore.Notes;

            for (var i = 0; i < notes.Count; i++)
            {
                if (notes[i].NoteType == NoteType.滑条a_结束)
                {
                    var sameTimeNotes = notes.Where(p => p.Time == notes[i].Time && p.Track != notes[i].Track).ToList();
                    if (sameTimeNotes.Count == 1 && sameTimeNotes[0].NoteType == NoteType.滑条a_开始)
                    {
                        sameTimeNotes[0].NoteType = NoteType.滑条b_开始;
                        for (int j = i + 1; j < notes.Count; j++)
                        {
                            if (notes[j].NoteType == NoteType.滑条a_中间)
                            {
                                notes[j].NoteType = NoteType.滑条b_中间;
                                continue;
                            }

                            if (notes[j].NoteType == NoteType.滑条a_结束)
                            {
                                notes[j].NoteType = NoteType.滑条b_结束;
                                break;
                            }

                            if (notes[j].NoteType == NoteType.滑条a_粉键结束)
                            {
                                notes[j].NoteType = NoteType.滑条b_粉键结束;
                                break;
                            }
                        }
                    }
                }

                if (notes[i].NoteType == NoteType.滑条b_结束)
                {
                    var sameTimeNotes = notes.Where(p => p.Time == notes[i].Time && p.Track != notes[i].Track).ToList();
                    if (sameTimeNotes.Count == 1 && sameTimeNotes[0].NoteType == NoteType.滑条b_开始)
                    {
                        sameTimeNotes[0].NoteType = NoteType.滑条a_开始;
                        for (int j = i + 1; j < notes.Count; j++)
                        {
                            if (notes[j].NoteType == NoteType.滑条b_中间)
                            {
                                notes[j].NoteType = NoteType.滑条a_中间;
                                continue;
                            }

                            if (notes[j].NoteType == NoteType.滑条b_结束)
                            {
                                notes[j].NoteType = NoteType.滑条a_结束;
                                break;
                            }

                            if (notes[j].NoteType == NoteType.滑条b_粉键结束)
                            {
                                notes[j].NoteType = NoteType.滑条a_粉键结束;
                                break;
                            }
                        }
                    }
                }
            }
        }
Пример #6
0
        /// <summary>
        ///     直ab绿条转长键
        /// </summary>
        /// <param name="defaultScore"></param>
        public void GenLongNote(DefaultScore defaultScore)
        {
            var notes = defaultScore.Notes;

            for (var i = 0; i < notes.Count; i++)
            {
                if (notes[i].NoteType == NoteType.滑条a_开始)
                {
                    var isLong = false;
                    for (var j = i + 1; j < notes.Count; j++)
                    {
                        if (notes[j].NoteType == NoteType.滑条a_中间)
                        {
                            break;
                        }

                        if (notes[j].NoteType == NoteType.滑条a_结束)
                        {
                            if (notes[j].Track == notes[i].Track)
                            {
                                isLong            = true;
                                notes[j].NoteType = NoteType.长键_结束;
                            }
                            break;
                        }

                        if (notes[j].NoteType == NoteType.滑条a_粉键结束)
                        {
                            if (notes[j].Track == notes[i].Track)
                            {
                                isLong            = true;
                                notes[j].NoteType = NoteType.长键_粉键结束;
                            }
                            break;
                        }
                    }

                    if (isLong)
                    {
                        notes[i].NoteType = NoteType.长键_开始;
                    }
                }

                if (notes[i].NoteType == NoteType.滑条b_开始)
                {
                    var isLong = false;
                    for (var j = i + 1; j < notes.Count; j++)
                    {
                        if (notes[j].NoteType == NoteType.滑条b_中间)
                        {
                            break;
                        }

                        if (notes[j].NoteType == NoteType.滑条b_结束)
                        {
                            if (notes[j].Track == notes[i].Track)
                            {
                                isLong            = true;
                                notes[j].NoteType = NoteType.长键_结束;
                            }
                            break;
                        }

                        if (notes[j].NoteType == NoteType.滑条b_粉键结束)
                        {
                            if (notes[j].Track == notes[i].Track)
                            {
                                isLong            = true;
                                notes[j].NoteType = NoteType.长键_粉键结束;
                            }
                            break;
                        }
                    }

                    if (isLong)
                    {
                        notes[i].NoteType = NoteType.长键_开始;
                    }
                }
            }
        }
Пример #7
0
        /// <summary>
        ///     从bandori database谱面json构造谱面对象
        /// </summary>
        /// <param name="scoreString">谱面文本</param>
        public DefaultScore GetDefaultScoreFromBandoriJson(string scoreString)
        {
            var defaultScore = new DefaultScore();
            var score        = JsonConvert.DeserializeObject <dynamic>(scoreString);

            defaultScore.Bpm      = score.metadata.bpm;
            defaultScore.Delay_ms = 0;
            var noteList = new List <Note>();

            foreach (var note in score.objects)
            {
                if (note.type == "System")
                {
                    continue;
                }
                var defaultNote = new Note
                {
                    Time  = note.beat + _delay,
                    Track = note.lane
                };

                if ((note.effect == "Single" || note.effect == "FeverSingle") && note.property == "Single")
                {
                    defaultNote.NoteType = NoteType.白键;
                    noteList.Add(defaultNote);
                    continue;
                }

                if (note.effect == "Skill" && note.property == "Single")
                {
                    defaultNote.NoteType = NoteType.技能;
                    noteList.Add(defaultNote);
                    continue;
                }

                if (note.effect == "Flick" && note.property == "Single")
                {
                    defaultNote.NoteType = NoteType.粉键;
                    noteList.Add(defaultNote);
                    continue;
                }

                if (note.effect == "SlideStart_A" && note.property == "Slide")
                {
                    defaultNote.NoteType = NoteType.滑条a_开始;
                    noteList.Add(defaultNote);
                    continue;
                }

                if (note.effect == "Slide_A" && note.property == "Slide")
                {
                    defaultNote.NoteType = NoteType.滑条a_中间;
                    noteList.Add(defaultNote);
                    continue;
                }

                if (note.effect == "SlideEnd_A" && note.property == "Slide")
                {
                    defaultNote.NoteType = NoteType.滑条a_结束;
                    noteList.Add(defaultNote);
                    continue;
                }

                if (note.effect == "SlideEndFlick_A" && note.property == "Slide")
                {
                    defaultNote.NoteType = NoteType.滑条a_粉键结束;
                    noteList.Add(defaultNote);
                    continue;
                }

                if (note.effect == "SlideStart_B" && note.property == "Slide")
                {
                    defaultNote.NoteType = NoteType.滑条b_开始;
                    noteList.Add(defaultNote);
                    continue;
                }

                if (note.effect == "Slide_B" && note.property == "Slide")
                {
                    defaultNote.NoteType = NoteType.滑条b_中间;
                    noteList.Add(defaultNote);
                    continue;
                }

                if (note.effect == "SlideEnd_B" && note.property == "Slide")
                {
                    defaultNote.NoteType = NoteType.滑条b_结束;
                    noteList.Add(defaultNote);
                    continue;
                }

                if ((note.effect == "Single" || note.effect == "Skill" || note.effect == "FeverSingle") &&
                    note.property == "LongStart")
                {
                    defaultNote.NoteType = NoteType.长键_开始;
                    noteList.Add(defaultNote);
                    continue;
                }

                if (note.effect == "Single" && note.property == "LongEnd")
                {
                    defaultNote.NoteType = NoteType.长键_结束;
                    noteList.Add(defaultNote);
                    continue;
                }

                if (note.effect == "Flick" && note.property == "LongEnd")
                {
                    defaultNote.NoteType = NoteType.长键_粉键结束;
                    noteList.Add(defaultNote);
                }
            }

            defaultScore.Notes = noteList;

            return(defaultScore);
        }
Пример #8
0
        /// <summary>
        ///     从bangbangboom谱面文本构造谱面对象
        /// </summary>
        /// <param name="scoreString">谱面文本</param>
        public DefaultScore GetDefaultScoreFromBangbangboomScore(string scoreString)
        {
            var defaultScore = new DefaultScore();
            var noteArray    = scoreString.Split("\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            var head         = noteArray[0].Split('|');

            defaultScore.Delay_ms = (int)(double.Parse(head[1]) * 1000);
            defaultScore.Bpm      = float.Parse(head[2]);

            var notes = new List <Note>();
            var isA   = true;

            for (var i = 1; i < noteArray.Length; i++)
            {
                var noteInfo = noteArray[i].Split('|');
                //白键
                if (noteInfo[0] == "s")
                {
                    var noteTimeAndTrack = noteInfo[1].Split(':');
                    notes.Add(new Note
                    {
                        NoteType = NoteType.白键,
                        Time     = double.Parse(noteTimeAndTrack[0]) / 24 + _delay,
                        Track    = int.Parse(noteTimeAndTrack[1]) + 1
                    });
                    continue;
                }

                //粉键
                if (noteInfo[0] == "f")
                {
                    var noteTimeAndTrack = noteInfo[1].Split(':');
                    notes.Add(new Note
                    {
                        NoteType = NoteType.粉键,
                        Time     = double.Parse(noteTimeAndTrack[0]) / 24 + _delay,
                        Track    = int.Parse(noteTimeAndTrack[1]) + 1
                    });
                    continue;
                }

                //非粉滑条
                if (noteInfo[0] == "l" && noteInfo[1] == "0")
                {
                    var startTimeAndTrack = noteInfo[2].Split(':');
                    notes.Add(new Note
                    {
                        NoteType = isA ? NoteType.滑条a_开始 : NoteType.滑条b_开始,
                        Time     = double.Parse(startTimeAndTrack[0]) / 24 + _delay,
                        Track    = int.Parse(startTimeAndTrack[1]) + 1
                    });
                    for (var j = 3; j < noteInfo.Length - 1; j++)
                    {
                        var noteTimeAndTrack = noteInfo[j].Split(':');
                        notes.Add(new Note
                        {
                            NoteType = isA ? NoteType.滑条a_中间 : NoteType.滑条b_中间,
                            Time     = double.Parse(noteTimeAndTrack[0]) / 24 + _delay,
                            Track    = int.Parse(noteTimeAndTrack[1]) + 1
                        });
                    }

                    var endTimeAndTrack = noteInfo[noteInfo.Length - 1].Split(':');
                    notes.Add(new Note
                    {
                        NoteType = isA ? NoteType.滑条a_结束 : NoteType.滑条b_结束,
                        Time     = double.Parse(endTimeAndTrack[0]) / 24 + _delay,
                        Track    = int.Parse(endTimeAndTrack[1]) + 1
                    });
                    isA = !isA;
                    continue;
                }

                //粉滑条
                if (noteInfo[0] == "l" && noteInfo[1] == "1")
                {
                    var startTimeAndTrack = noteInfo[2].Split(':');
                    notes.Add(new Note
                    {
                        NoteType = isA ? NoteType.滑条a_开始 : NoteType.滑条b_开始,
                        Time     = double.Parse(startTimeAndTrack[0]) / 24 + _delay,
                        Track    = int.Parse(startTimeAndTrack[1]) + 1
                    });
                    for (var j = 3; j < noteInfo.Length - 1; j++)
                    {
                        var noteTimeAndTrack = noteInfo[j].Split(':');
                        notes.Add(new Note
                        {
                            NoteType = isA ? NoteType.滑条a_中间 : NoteType.滑条b_中间,
                            Time     = double.Parse(noteTimeAndTrack[0]) / 24 + _delay,
                            Track    = int.Parse(noteTimeAndTrack[1]) + 1
                        });
                    }

                    var endTimeAndTrack = noteInfo[noteInfo.Length - 1].Split(':');
                    notes.Add(new Note
                    {
                        NoteType = isA ? NoteType.滑条a_粉键结束 : NoteType.滑条b_粉键结束,
                        Time     = double.Parse(endTimeAndTrack[0]) / 24 + _delay,
                        Track    = int.Parse(endTimeAndTrack[1]) + 1
                    });
                    isA = !isA;
                }
            }

            //先按时间排,然后按轨道从左到右排
            defaultScore.Notes = notes.OrderBy(p => p.Time).ThenBy(p => p.Track).ToList();
            return(defaultScore);
        }