Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/games/gomoku gomoku: condense code to decide which spot is b...



details:   https://anonhg.NetBSD.org/src/rev/7e952f8d63cc
branches:  trunk
changeset: 366159:7e952f8d63cc
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon May 16 19:20:25 2022 +0000

description:
gomoku: condense code to decide which spot is better

The comments in the conditions only serve to align the expressions, to
allow humans to check that they correspond.

No functional change.

diffstat:

 games/gomoku/pickmove.c |  53 +++++++++++++++++-------------------------------
 1 files changed, 19 insertions(+), 34 deletions(-)

diffs (79 lines):

diff -r d56298ed16cc -r 7e952f8d63cc games/gomoku/pickmove.c
--- a/games/gomoku/pickmove.c   Mon May 16 18:44:38 2022 +0000
+++ b/games/gomoku/pickmove.c   Mon May 16 19:20:25 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pickmove.c,v 1.27 2022/05/15 22:41:51 rillig Exp $     */
+/*     $NetBSD: pickmove.c,v 1.28 2022/05/16 19:20:25 rillig Exp $     */
 
 /*
  * Copyright (c) 1994
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)pickmove.c 8.2 (Berkeley) 5/3/95";
 #else
-__RCSID("$NetBSD: pickmove.c,v 1.27 2022/05/15 22:41:51 rillig Exp $");
+__RCSID("$NetBSD: pickmove.c,v 1.28 2022/05/16 19:20:25 rillig Exp $");
 #endif
 #endif /* not lint */
 
@@ -194,43 +194,28 @@
 {
        int them, s, s1;
 
-       if (sp->s_combo[us].s < sp1->s_combo[us].s)
-               return 1;
-       if (sp->s_combo[us].s != sp1->s_combo[us].s)
-               return 0;
-       if (sp->s_level[us] < sp1->s_level[us])
-               return 1;
-       if (sp->s_level[us] != sp1->s_level[us])
-               return 0;
-       if (sp->s_nforce[us] > sp1->s_nforce[us])
-               return 1;
-       if (sp->s_nforce[us] != sp1->s_nforce[us])
-               return 0;
+       if (/* .... */ sp->s_combo[us].s != sp1->s_combo[us].s)
+               return sp->s_combo[us].s < sp1->s_combo[us].s;
+       if (/* .... */ sp->s_level[us] != sp1->s_level[us])
+               return sp->s_level[us] < sp1->s_level[us];
+       if (/* .... */ sp->s_nforce[us] != sp1->s_nforce[us])
+               return sp->s_nforce[us] > sp1->s_nforce[us];
 
        them = !us;
        s = sp - board;
        s1 = sp1 - board;
-       if (BIT_TEST(forcemap, s) && !BIT_TEST(forcemap, s1))
-               return 1;
-       if (!BIT_TEST(forcemap, s) && BIT_TEST(forcemap, s1))
-               return 0;
-       if (sp->s_combo[them].s < sp1->s_combo[them].s)
-               return 1;
-       if (sp->s_combo[them].s != sp1->s_combo[them].s)
-               return 0;
-       if (sp->s_level[them] < sp1->s_level[them])
-               return 1;
-       if (sp->s_level[them] != sp1->s_level[them])
-               return 0;
-       if (sp->s_nforce[them] > sp1->s_nforce[them])
-               return 1;
-       if (sp->s_nforce[them] != sp1->s_nforce[them])
-               return 0;
+       if ((BIT_TEST(forcemap, s) != 0) != (BIT_TEST(forcemap, s1) != 0))
+               return BIT_TEST(forcemap, s) != 0;
 
-       if (sp->s_wval > sp1->s_wval)
-               return 1;
-       if (sp->s_wval != sp1->s_wval)
-               return 0;
+       if (/* .... */ sp->s_combo[them].s != sp1->s_combo[them].s)
+               return sp->s_combo[them].s < sp1->s_combo[them].s;
+       if (/* .... */ sp->s_level[them] != sp1->s_level[them])
+               return sp->s_level[them] < sp1->s_level[them];
+       if (/* .... */ sp->s_nforce[them] != sp1->s_nforce[them])
+               return sp->s_nforce[them] > sp1->s_nforce[them];
+
+       if (/* .... */ sp->s_wval != sp1->s_wval)
+               return sp->s_wval > sp1->s_wval;
 
        return random() & 1;
 }



Home | Main Index | Thread Index | Old Index