Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/games/dab Rename .C files to .cc
details: https://anonhg.NetBSD.org/src/rev/9fd632c4f589
branches: trunk
changeset: 556781:9fd632c4f589
user: christos <christos%NetBSD.org@localhost>
date: Sat Dec 27 01:16:55 2003 +0000
description:
Rename .C files to .cc
diffstat:
games/dab/Makefile | 6 +-
games/dab/algor.C | 314 ------------------------------------------------
games/dab/algor.cc | 314 ++++++++++++++++++++++++++++++++++++++++++++++++
games/dab/board.C | 260 ---------------------------------------
games/dab/board.cc | 260 +++++++++++++++++++++++++++++++++++++++
games/dab/box.C | 157 ------------------------
games/dab/box.cc | 157 ++++++++++++++++++++++++
games/dab/gamescreen.C | 50 -------
games/dab/gamescreen.cc | 50 +++++++
games/dab/human.C | 151 -----------------------
games/dab/human.cc | 151 +++++++++++++++++++++++
games/dab/main.C | 196 -----------------------------
games/dab/main.cc | 196 +++++++++++++++++++++++++++++
games/dab/player.C | 98 --------------
games/dab/player.cc | 98 ++++++++++++++
games/dab/random.C | 86 -------------
games/dab/random.cc | 86 +++++++++++++
games/dab/test.C | 57 --------
games/dab/test.cc | 57 ++++++++
games/dab/ttyscrn.C | 235 -----------------------------------
games/dab/ttyscrn.cc | 235 +++++++++++++++++++++++++++++++++++
21 files changed, 1607 insertions(+), 1607 deletions(-)
diffs (truncated from 3307 to 300 lines):
diff -r 833fd89115f9 -r 9fd632c4f589 games/dab/Makefile
--- a/games/dab/Makefile Sat Dec 27 00:58:35 2003 +0000
+++ b/games/dab/Makefile Sat Dec 27 01:16:55 2003 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.1.1.1 2003/12/26 17:57:02 christos Exp $
+# $NetBSD: Makefile,v 1.2 2003/12/27 01:16:55 christos Exp $
WARNS=2
DPADD+=${LIBSTDCPP} ${LIBCURSES} ${LIBTERMCAP} ${LIBM}
@@ -6,7 +6,7 @@
PROG=dab
MAN=dab.6
-SRCS=algor.C board.C main.C human.C box.C player.C gamescreen.C \
- ttyscrn.C random.C
+SRCS=algor.cc board.cc main.cc human.cc box.cc player.cc gamescreen.cc \
+ ttyscrn.cc random.cc
.include <bsd.prog.mk>
diff -r 833fd89115f9 -r 9fd632c4f589 games/dab/algor.C
--- a/games/dab/algor.C Sat Dec 27 00:58:35 2003 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,314 +0,0 @@
-/* $NetBSD: algor.C,v 1.2 2003/12/26 18:03:34 christos Exp $ */
-
-/*-
- * Copyright (c) 2003 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Christos Zoulas.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the NetBSD
- * Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * algor.C: Computer algorithm
- */
-#include "defs.h"
-RCSID("$NetBSD: algor.C,v 1.2 2003/12/26 18:03:34 christos Exp $")
-
-#include "algor.h"
-#include "board.h"
-#include "box.h"
-#include "random.h"
-
-ALGOR::ALGOR(const char c) : PLAYER(c)
-{
-#ifdef notyet
- // Single Edges = (x + y) * 2
- _edge1 = (_b.nx() * _b.ny()) * 2;
- // Shared Edges = (x * (y - 1)) + ((x - 1) * y)
- _edge2 = (_b.nx() * (_b.ny() - 1)) + ((_b.nx() - 1) * _b.ny());
- // Maximum Edges filled before closure = x * y * 2
- _maxedge = _b.nx() * _b.ny() * 2;
-#endif
-}
-
-// Find the first closure, i.e. a box that has 3 edges
-int ALGOR::find_closure(size_t& y, size_t& x, int& dir, BOARD& b)
-{
- RANDOM rdy(b.ny()), rdx(b.nx());
-
- for (y = rdy(); y < b.ny(); y = rdy()) {
- rdx.clear();
- for (x = rdx(); x < b.nx(); x = rdx()) {
- BOX box(y, x, b);
- if (box.count() == 3) {
- for (dir = BOX::first; dir < BOX::last; dir++)
- if (!box.isset(dir))
- return 1;
- b.abort("find_closure: 3 sided box[%d,%d] has no free sides",
- y, x);
- }
- }
- }
- return 0;
-}
-
-#if 0
-size_t ALGOR::find_single()
-{
- size_t ne;
-
- // Find the number of single edges in use
- for (size_t x = 0; x < b.nx(); x++) {
- BOX tbox(0, x, b);
- ne += tbox.isset(BOX::top);
- BOX bbox(b.ny() - 1, x, b);
- ne += bbox.isset(BOX::bottom);
- }
- for (size_t y = 0; y < _b.ny(); y++) {
- BOX lbox(y, 0, b);
- ne += lbox.isset(BOX::left);
- BOX rbox(y,_b.nx() - 1, b);
- ne += rbox.isset(BOX::right);
- }
- return ne;
-}
-#endif
-
-
-// Count a closure, by counting all boxes that we can close in the current
-// move
-size_t ALGOR::count_closure(size_t& y, size_t& x, int& dir, BOARD& b)
-{
- size_t i = 0;
- size_t tx, ty;
- int tdir, mv;
-
- while (find_closure(ty, tx, tdir, b)) {
- if (i == 0) {
- // Mark the beginning of the closure
- x = tx;
- y = ty;
- dir = tdir;
- }
- if ((mv = b.domove(ty, tx, tdir, getWho())) == -1)
- b.abort("count_closure: Invalid move (%d, %d, %d)", y, x, dir);
- else
- i += mv;
- }
- return i;
-}
-
-
-/*
- * Find the largest closure, by closing all possible closures.
- * return the number of boxes closed in the maximum closure,
- * and the first box of the maximum closure in (x, y, dir)
- */
-int ALGOR::find_max_closure(size_t& y, size_t& x, int& dir, const BOARD& b)
-{
- BOARD nb(b);
- int tdir, maxdir = -1;
- size_t nbox, maxbox = 0;
- size_t tx, ty, maxx = ~0, maxy = ~0;
-
- while ((nbox = count_closure(ty, tx, tdir, nb)) != 0)
- if (nbox > maxbox) {
- // This closure is better, update max
- maxbox = nbox;
- maxx = tx;
- maxy = ty;
- maxdir = tdir;
- }
-
- // Return the max found
- y = maxy;
- x = maxx;
- dir = maxdir;
- return maxbox;
-}
-
-
-// Find if a turn does not result in a capture on the given box
-// and return the direction if found.
-int ALGOR::try_good_turn(BOX& box, size_t y, size_t x, int& dir, BOARD& b)
-{
- // Sanity check; we must have a good box
- if (box.count() >= 2)
- b.abort("try_good_turn: box[%d,%d] has more than 2 sides occupied",
- y, x);
-
- // Make sure we don't make a closure in an adjacent box.
- // We use a random direction to randomize the game
- RANDOM rd(BOX::last);
- for (dir = rd(); dir < BOX::last; dir = rd())
- if (!box.isset(dir)) {
- size_t by = y + BOX::edges[dir].y;
- size_t bx = x + BOX::edges[dir].x;
- if (!b.bounds(by, bx))
- return 1;
-
- BOX nbox(by, bx, b);
- if (nbox.count() < 2)
- return 1;
- }
-
- return 0;
-}
-
-
-// Try to find a turn that does not result in an opponent closure, and
-// return it in (x, y, dir); if not found return 0.
-int ALGOR::find_good_turn(size_t& y, size_t& x, int& dir, const BOARD& b)
-{
- BOARD nb(b);
- RANDOM rdy(b.ny()), rdx(b.nx());
-
- for (y = rdy(); y < b.ny(); y = rdy()) {
- rdx.clear();
- for (x = rdx(); x < b.nx(); x = rdx()) {
- BOX box(y, x, nb);
- if (box.count() < 2 && try_good_turn(box, y, x, dir, nb))
- return 1;
- }
- }
- return 0;
-}
-
-// On a box with 2 edges, return the first or the last free edge, depending
-// on the order specified
-int ALGOR::try_bad_turn(BOX& box, size_t& y, size_t& x, int& dir, BOARD& b,
- int last)
-{
- if (4 - box.count() <= last)
- b.abort("try_bad_turn: Called at [%d,%d] for %d with %d",
- y, x, last, box.count());
- for (dir = BOX::first; dir < BOX::last; dir++)
- if (!box.isset(dir)) {
- if (!last)
- return 1;
- else
- last--;
- }
- return 0;
-}
-
-// Find a box that has 2 edges and return the first free edge of that
-// box or the last free edge of that box
-int ALGOR::find_bad_turn(size_t& y, size_t& x, int& dir, BOARD& b, int last)
-{
- RANDOM rdy(b.ny()), rdx(b.nx());
- for (y = rdy(); y < b.ny(); y = rdy()) {
- rdx.clear();
- for (x = rdx(); x < b.nx(); x = rdx()) {
- BOX box(y, x, b);
- if ((4 - box.count()) > last &&
- try_bad_turn(box, y, x, dir, b, last))
- return 1;
- }
- }
- return 0;
-}
-
-int ALGOR::find_min_closure1(size_t& y, size_t& x, int& dir, const BOARD& b,
- int last)
-{
- BOARD nb(b);
- int tdir, mindir = -1, xdir, mv;
- // number of boxes per closure
- size_t nbox, minbox = nb.nx() * nb.ny() + 1;
- size_t tx, ty, minx = ~0, miny = ~0;
-
- while (find_bad_turn(ty, tx, tdir, nb, last)) {
-
- // Play a bad move that would cause the opponent's closure
- if ((mv = nb.domove(ty, tx, tdir, getWho())) != 0)
- b.abort("find_min_closure1: Invalid move %d (%d, %d, %d)", mv,
- ty, tx, tdir);
-
- // Count the opponent's closure
- if ((nbox = count_closure(y, x, xdir, nb)) == 0)
- b.abort("find_min_closure1: no closure found");
-
- if (nbox <= minbox) {
- // This closure has fewer boxes
- minbox = nbox;
- minx = tx;
- miny = ty;
- mindir = tdir;
- }
- }
-
- y = miny;
- x = minx;
- dir = mindir;
- return minbox;
-}
-
-
-// Search for the move that makes the opponent close the least number of
-// boxes; returns 1 if a move found, 0 otherwise
Home |
Main Index |
Thread Index |
Old Index