xref: /netbsd-src/games/dab/algor.h (revision 2824f617346f3d8892743bf0d8a43e32733b33ac)
1*2824f617Srillig /*	$NetBSD: algor.h,v 1.6 2021/12/05 09:22:45 rillig Exp $	*/
2e30af347Schristos 
3e30af347Schristos /*-
4e30af347Schristos  * Copyright (c) 2003 The NetBSD Foundation, Inc.
5e30af347Schristos  * All rights reserved.
6e30af347Schristos  *
7e30af347Schristos  * This code is derived from software contributed to The NetBSD Foundation
8e30af347Schristos  * by Christos Zoulas.
9e30af347Schristos  *
10e30af347Schristos  * Redistribution and use in source and binary forms, with or without
11e30af347Schristos  * modification, are permitted provided that the following conditions
12e30af347Schristos  * are met:
13e30af347Schristos  * 1. Redistributions of source code must retain the above copyright
14e30af347Schristos  *    notice, this list of conditions and the following disclaimer.
15e30af347Schristos  * 2. Redistributions in binary form must reproduce the above copyright
16e30af347Schristos  *    notice, this list of conditions and the following disclaimer in the
17e30af347Schristos  *    documentation and/or other materials provided with the distribution.
18e30af347Schristos  *
19e30af347Schristos  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20e30af347Schristos  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21e30af347Schristos  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22e30af347Schristos  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23e30af347Schristos  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24e30af347Schristos  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25e30af347Schristos  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26e30af347Schristos  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27e30af347Schristos  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28e30af347Schristos  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29e30af347Schristos  * POSSIBILITY OF SUCH DAMAGE.
30e30af347Schristos  */
31e30af347Schristos 
32e30af347Schristos /*
33*2824f617Srillig  * Computer's algorithm
34e30af347Schristos  */
35e30af347Schristos 
36e30af347Schristos #ifndef _H_ALGOR
37e30af347Schristos #define _H_ALGOR
38e30af347Schristos 
39e30af347Schristos #include "player.h"
40e30af347Schristos 
41e30af347Schristos class BOARD;
42e30af347Schristos class BOX;
43e30af347Schristos 
44e30af347Schristos class ALGOR : public PLAYER {
45e30af347Schristos   public:
46e30af347Schristos     ALGOR(const char c);
~ALGOR()47ef47ce82Schristos     virtual ~ALGOR() {}
48e30af347Schristos     // Return a proposed move in (y, x, dir)
49e30af347Schristos     void play(const BOARD& b, size_t& y, size_t& x, int& dir);
50e30af347Schristos 
51e30af347Schristos   private:
52e30af347Schristos     // Closure searches
53e30af347Schristos     int find_closure(size_t& y, size_t& x, int& dir, BOARD& b);
5456c9d385Schristos     size_t find_max_closure(size_t& y, size_t& x, int& dir, const BOARD& b);
5556c9d385Schristos     size_t find_min_closure1(size_t& y, size_t& x, int& dir, const BOARD& b,
56e30af347Schristos 	int last);
5756c9d385Schristos     size_t find_min_closure(size_t& y, size_t& x, int& dir, const BOARD& b);
58e30af347Schristos 
59e30af347Schristos     // Move searches
60e30af347Schristos     int find_good_turn(size_t& y, size_t& x, int& dir, const BOARD& b);
61e30af347Schristos     int find_bad_turn(size_t& y, size_t& x, int& dir, BOARD& b, int last);
62e30af347Schristos 
63e30af347Schristos     // Move Attempts
64e30af347Schristos     int try_bad_turn(BOX& box, size_t& y, size_t& x, int& dir, BOARD& b,
65e30af347Schristos 		     int last);
66e30af347Schristos     int try_good_turn(BOX& box, size_t y, size_t x, int& dir, BOARD& b);
67e30af347Schristos 
68e30af347Schristos     // Utils
69e30af347Schristos     size_t count_closure(size_t& y, size_t& x, int& dir, BOARD& b);
70e30af347Schristos 
71e30af347Schristos #ifdef notyet
72e30af347Schristos     size_t find_single(void);
73e30af347Schristos #endif
74e30af347Schristos };
75e30af347Schristos 
76e30af347Schristos #endif
77