@@ -46,6 +46,8 @@ struct MultiJump {
4646// WorkingBuffer can also be reset for reuse with another kwg by calling
4747// reset_for_another_kwg().
4848// This is not enforced.
49+ type AlphaCacheEntry = ( [ u8 ; 64 ] , bool ) ;
50+
4951struct WorkingBuffer {
5052 rack_tally : Box < [ u8 ] > , // 27 for ?A-Z
5153 word_buffer_for_across_plays : Box < [ u8 ] > , // r*c
@@ -90,7 +92,7 @@ struct WorkingBuffer {
9092 best_leave_values : Vec < f32 > , // rack.len() + 1
9193 found_placements : Vec < PossiblePlacement > ,
9294 used_letters_tally : Vec < u8 > , // 27 for ?A-Z, ? is always 0, jumbled mode only
93- accepts_alpha_cache : Box < [ ( [ u8 ; 64 ] , bool ) ] > , // jumbled mode only
95+ accepts_alpha_cache : Option < Box < [ AlphaCacheEntry ] > > , // jumbled mode only
9496 used_tile_scores_shadowl : Vec < i8 > , // rack.len() (for shadow_play_left)
9597 used_tile_scores_shadowr : Vec < i8 > , // rack.len() (for shadow_play_right)
9698 rack_tally_shadowl : Box < [ u8 ] > , // 27 for ?A-Z (for shadow_play_left)
@@ -358,7 +360,7 @@ impl WorkingBuffer {
358360 best_leave_values : Vec :: new ( ) ,
359361 found_placements : Vec :: new ( ) ,
360362 used_letters_tally : Vec :: new ( ) ,
361- accepts_alpha_cache : vec ! [ ( [ 0u8 ; 64 ] , false ) ; 128 ] . into_boxed_slice ( ) ,
363+ accepts_alpha_cache : None ,
362364 used_tile_scores_shadowl : Vec :: new ( ) ,
363365 used_tile_scores_shadowr : Vec :: new ( ) ,
364366 rack_tally_shadowl : vec ! [ 0u8 ; game_config. alphabet( ) . len( ) as usize ] . into_boxed_slice ( ) ,
@@ -524,6 +526,10 @@ impl WorkingBuffer {
524526 game_config:: GameRules :: Classic => { }
525527 game_config:: GameRules :: Jumbled => {
526528 self . used_letters_tally . resize ( alphabet. len ( ) as usize , 0 ) ;
529+ if self . accepts_alpha_cache . is_none ( ) {
530+ self . accepts_alpha_cache =
531+ Some ( vec ! [ ( [ 0u8 ; 64 ] , false ) ; 128 ] . into_boxed_slice ( ) ) ;
532+ }
527533 }
528534 }
529535 self . used_tile_scores_shadowl . clear ( ) ;
@@ -596,7 +602,9 @@ impl WorkingBuffer {
596602 self . right_extension_set_for_across_plays . fill ( !0u64 ) ;
597603 self . left_extension_set_for_down_plays . fill ( !0u64 ) ;
598604 self . right_extension_set_for_down_plays . fill ( !0u64 ) ;
599- self . accepts_alpha_cache . fill ( ( [ 0u8 ; 64 ] , false ) ) ;
605+ if let Some ( cache) = & mut self . accepts_alpha_cache {
606+ cache. fill ( ( [ 0u8 ; 64 ] , false ) ) ;
607+ }
600608 }
601609}
602610
@@ -1537,7 +1545,7 @@ struct GenPlaceMovesParams<'a, CallbackType: FnMut(i8, &[u8], i32, f32), N: kwg:
15371545 num_tiles_in_bag : i16 ,
15381546 play_out_bonus : f32 ,
15391547 used_letters_tally : & ' a mut [ u8 ] , // jumbled mode only
1540- accepts_alpha_cache : & ' a mut [ ( [ u8 ; 64 ] , bool ) ] , // jumbled mode only
1548+ accepts_alpha_cache : & ' a mut [ AlphaCacheEntry ] , // jumbled mode only
15411549}
15421550
15431551fn gen_classic_place_moves <
@@ -2314,7 +2322,10 @@ fn gen_place_moves_at<
23142322 num_tiles_in_bag : working_buffer. num_tiles_in_bag ,
23152323 play_out_bonus : working_buffer. play_out_bonus ,
23162324 used_letters_tally : & mut working_buffer. used_letters_tally ,
2317- accepts_alpha_cache : & mut working_buffer. accepts_alpha_cache ,
2325+ accepts_alpha_cache : working_buffer
2326+ . accepts_alpha_cache
2327+ . as_deref_mut ( )
2328+ . unwrap_or ( & mut [ ] ) ,
23182329 } ,
23192330 !placement. down ,
23202331 ) ;
0 commit comments