@@ -270,12 +270,12 @@ impl Board {
270270 if vacant
271271 . iter ( )
272272 . map ( |coord| Play ( color, coord. col , coord. row ) )
273- . any ( |m| !self . is_eye ( & m. coord ( ) , * m. color ( ) ) && self . playout_legal_move ( m ) ) {
273+ . any ( |m| !self . is_eye ( & m. coord ( ) , * m. color ( ) ) && self . is_legal ( m ) . is_ok ( ) ) {
274274 //while loop testing all vacant spots
275275 loop {
276276 let random_vacant = vacant[ rng. gen :: < usize > ( ) % vacant. len ( ) ] ;
277277 let random_play = Play ( color, random_vacant. col , random_vacant. row ) ;
278- if !self . is_eye ( & random_vacant, color) && self . playout_legal_move ( random_play) {
278+ if !self . is_eye ( & random_vacant, color) && self . is_legal ( random_play) . is_ok ( ) {
279279 return random_play;
280280 }
281281 }
@@ -285,41 +285,6 @@ impl Board {
285285 }
286286 }
287287
288- fn playout_legal_move ( & self , m : Move ) -> bool {
289- // Can't play on a Ko point
290- if self . ko . is_some ( ) && m. coord ( ) == self . ko . unwrap ( ) {
291- if self . neighbours ( m. coord ( ) ) //neighbours of the coordinate of the ko point
292- . iter ( )
293- . filter ( |& c| self . color ( c) == m. color ( ) . opposite ( ) ) //accept coordinates of opposite stones
294- . map ( |& c| self . get_chain ( c) . unwrap ( ) ) //get the chain of those opposite stones
295- . any ( |chain| chain. liberties ( ) . len ( ) == 1 && chain. coords ( ) . len ( ) == 1 ) { //if any of them has one liberty and one stone
296- return false ;
297- }
298- }
299- // Can't play suicide move
300- if !self . ruleset . suicide_allowed ( ) {
301- // All neighbours must be occupied
302- if self . neighbours ( m. coord ( ) ) . iter ( ) . all ( |c| self . color ( c) != Empty ) {
303- // A move is a suicide move if all of the opposing,
304- // neighbouring chain has more than one liberty and all of
305- // our own chains have only one liberty.
306- let enemy_chains_with_other_libs = self . neighbours ( m. coord ( ) )
307- . iter ( )
308- . filter ( |& c| self . color ( c) == m. color ( ) . opposite ( ) )
309- . all ( |& c| self . get_chain ( c) . unwrap ( ) . liberties ( ) . len ( ) > 1 ) ;
310- let own_chains_without_other_libs = self . neighbours ( m. coord ( ) )
311- . iter ( )
312- . filter ( |& c| self . color ( c) == * m. color ( ) )
313- . all ( |& c| self . get_chain ( c) . unwrap ( ) . liberties ( ) . len ( ) <= 1 ) ;
314- if enemy_chains_with_other_libs && own_chains_without_other_libs {
315- return false ;
316- }
317- }
318- }
319-
320- true
321- }
322-
323288 //#[inline(never)] //turn off for profiling
324289 pub fn legal_moves_without_eyes ( & self ) -> Vec < Move > {
325290 self . legal_moves_without_superko_check ( )
0 commit comments