@@ -116,9 +116,11 @@ static IEnumerable<Entry> Canon(IReadOnlyList<Entry> e) =>
116116 }
117117 }
118118
119- [ GeneratedRegex ( @"\[(?:(\d+):(\d+)|#([\d\.]+))\]" ) ]
119+ [ GeneratedRegex ( @"\[(?:(\d+):(\d+)|(?:([\d\.]+)#)? #([\d\.]+))\]" ) ]
120120 private static partial Regex DurationStrRegex ( ) ;
121121
122+ private static bool Near ( double a , double b ) => Math . Abs ( a - b ) < 1e-3 ;
123+
122124 private static void AssertNoteEqual ( string expected , string actual , int noteIdx , Rational time , Chart chart )
123125 {
124126 var expArr = RearrangeNote ( expected ) . Split ( '/' , '`' ) ;
@@ -137,11 +139,27 @@ private static void AssertNoteEqual(string expected, string actual, int noteIdx,
137139 var expTime = DurationStrRegex ( ) . Match ( exp ) ;
138140 var actTime = DurationStrRegex ( ) . Match ( act ) ;
139141 var bpm = chart . BpmList . Find ( time ) . Bpm ;
140- if ( expTime . Groups [ 1 ] . Success && actTime . Groups [ 3 ] . Success )
142+ if ( expTime . Groups [ 1 ] . Success && actTime . Groups [ 4 ] . Success )
141143 { // exp中是分数时间、act中是小数时间的情况
142144 // 小数时间化为分数时间,看看是否对的上
143- var v = decimal . Parse ( actTime . Groups [ 3 ] . Value ) / ( 240 / bpm ) * int . Parse ( expTime . Groups [ 1 ] . Value ) ;
144- if ( Math . Round ( v ) == int . Parse ( expTime . Groups [ 2 ] . Value ) ) result = true ; // 如果对的上,则不判定为比较失败
145+ var numer = decimal . Parse ( actTime . Groups [ 4 ] . Value ) / ( 240 / bpm ) * int . Parse ( expTime . Groups [ 1 ] . Value ) ;
146+ if ( Math . Round ( numer ) == int . Parse ( expTime . Groups [ 2 ] . Value ) ) result = true ; // 如果对的上,则不判定为比较失败
147+ if ( actTime . Groups [ 3 ] . Success )
148+ { // 如果写了等待时间的话,等待时间必须为1拍
149+ var oneBeatSec = 60 / ( Rational ) bpm ;
150+ if ( ! Near ( double . Parse ( actTime . Groups [ 3 ] . Value ) , ( double ) oneBeatSec ) ) result = false ; // 如果等待时间对不上,则仍判定为比较失败
151+ }
152+ }
153+ else if ( actTime . Groups [ 1 ] . Success && expTime . Groups [ 4 ] . Success )
154+ { // exp中是小数时间、act中是分数时间的情况
155+ // 分数时间化为小数时间,看是否对的上(差距<1ms)
156+ var sec = new Rational ( int . Parse ( actTime . Groups [ 2 ] . Value ) , int . Parse ( actTime . Groups [ 1 ] . Value ) ) * ( 240 / ( Rational ) bpm ) ;
157+ if ( Near ( ( double ) sec , double . Parse ( expTime . Groups [ 4 ] . Value ) ) ) result = true ; // 如果对的上,则不判定为比较失败
158+ if ( expTime . Groups [ 3 ] . Success )
159+ { // 如果写了等待时间的话,等待时间必须为1拍
160+ var oneBeatSec = 60 / ( Rational ) bpm ;
161+ if ( ! Near ( double . Parse ( expTime . Groups [ 3 ] . Value ) , ( double ) oneBeatSec ) ) result = false ; // 如果等待时间对不上,则仍判定为比较失败
162+ }
145163 }
146164 }
147165
0 commit comments