/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
* This is GNU Go, a Go program. Contact gnugo@gnu.org, or see *
* http://www.gnu.org/software/gnugo/ for more information. *
* Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, *
* 2008 and 2009 by the Free Software Foundation. *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation - version 3 or *
* (at your option) any later version. *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License in file COPYING for more details. *
* You should have received a copy of the GNU General Public *
* License along with this program; if not, write to the Free *
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02111, USA. *
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void movelist_sort_points(int max_points
, int points
[], int codes
[]);
static void swap_points_and_codes(int points
[], int codes
[], int m
, int n
);
/* Return the code for the move if it is known.
movelist_move_known(int move
, int max_points
, int points
[], int codes
[])
for (k
= 0; k
< max_points
; k
++) {
* This function does the real work for change_attack(),
* change_defense(), change_attack_threat(), and
* change_defense_threat().
movelist_change_point(int move
, int code
, int max_points
,
int points
[], int codes
[])
/* First see if we already know about this point. */
for (k
= 0; k
< max_points
; k
++)
movelist_sort_points(max_points
, points
, codes
);
/* This tactical point is new to us. */
if (code
> codes
[max_points
- 1]) {
points
[max_points
- 1] = move
;
codes
[max_points
- 1] = code
;
movelist_sort_points(max_points
, points
, codes
);
/* Sort the tactical points so we have it sorted in falling order on
* We use shaker sort because we prefer a stable sort and in all use
* cases we can expect it to suffice with one turn through the outer
movelist_sort_points(int max_points
, int points
[], int codes
[])
int end
= max_points
- 1;
for (k
= end
; k
> start
; k
--)
if (codes
[k
] > codes
[k
-1]) {
swap_points_and_codes(points
, codes
, k
, k
-1);
for (k
= start
; k
< end
- 1; k
++)
if (codes
[k
] < codes
[k
+1]) {
swap_points_and_codes(points
, codes
, k
, k
+1);
swap_points_and_codes(int points
[], int codes
[], int m
, int n
)