⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 checkers_hole.hpp

📁 本程序是主要是扫雷
💻 HPP
字号:
/*     Copyright(c) Ben Bear 2003-2004  */

//  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; either version 2 of the
//  License, 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 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., 59 Temple Place - Suite 330, Boston, MA
//  02111-1307, USA.

#ifndef __checkers_hole_hpp
#define __checkers_hole_hpp

#include <cassert>

#include "honey_hole.hpp"

const int CHECKERS_HOLE_ERROR = -1;

class checkers_hole: public honey_hole
{
protected:
  // checkers' max _floor, normal is 8
  // accordding to number of one player's chesses
  // floor should >= 6, and even
  int floor;

public:
  explicit
  checkers_hole (int f, int n = 0)
    : honey_hole(n), floor(f)
  {
    assert((f > 0) && (f % 2 == 0));

    in() ? : _No = CHECKERS_HOLE_ERROR;
  }
  
  checkers_hole& operator= (const honey_hole& h)
  {
    _No = h;
    return *this;
  }

  checkers_hole& operator = (int n)
  {
    set (n);
    return *this;
  }

  operator int () const { return _No; }

  // set a new hole value
  checkers_hole& set (int n = 0);

  // move at direction[dir] and some [step]
  checkers_hole& move (int dir, int step = 1);

  // jump over hole[h]
  checkers_hole& jump (honey_hole h);

  // if this hole is in the checkers, return true
  bool in() const;
  // if hole[h] is in this checkers, return true
  bool in(int h) const;
  // if hole[h] is in the checkers[floor = f], return true
  static bool in(int f, int h);

  static bool inside(int f, int h);
  static bool inside(int f, int h, int d);
};

checkers_hole&
checkers_hole::set (int n)
{
  honey_hole::set (n);
  if (!in())
    _No = CHECKERS_HOLE_ERROR;
  return *this;
}

checkers_hole&
checkers_hole::move (int dir, int step)
{
  honey_hole::move (dir, step);
  if (!in())
    _No = CHECKERS_HOLE_ERROR;
  return *this;
}

bool
checkers_hole::in() const
{
  if (_No == CHECKERS_HOLE_ERROR)
    return false;

  int f, s, o;
  get (f, s, o);
  if ((f <= floor / 2) || ((f - floor / 2 <= o) && (o <= floor / 2)))
    return true;
  else
    return false;
}

bool
checkers_hole::in (int h) const
{
  if (h == CHECKERS_HOLE_ERROR)
    return false;
  return checkers_hole(floor, h).in();
}

bool
checkers_hole::in (int f, int h)
{
  if (h == CHECKERS_HOLE_ERROR)
    return false;
  checkers_hole hole(f, h);
  return hole.in();
}

/*
bool
checkers_hole::in(int n)
{
  if (!in())
    return false;
  int f, s, o;
  get (f, s, o);
  if ((f > 4) && (n != s) && ((n + 3) % 6 != s))
    return false;
  return true;
}
*/

bool
checkers_hole::inside (int f, int h)
{
  if (h == CHECKERS_HOLE_ERROR)
    return false;
  if (h == 0)
    return true;
  int _f, _s, _o;
  honey_hole(h).get(_f, _s, _o);
  return (_o != 0) && (_f <= (f / 2));
}

bool
checkers_hole::inside (int f, int h, int d)
{
  if (h == CHECKERS_HOLE_ERROR)
    return false;
  if (h == 0)
    return true;
  int _f, _s, _o;
  honey_hole(h).get(_f, _s, _o);
  return ((_f <= (f / 2)) 
	  || ((_s == d) || (_s + 3 == d) || (d + 3 == _s)));
}

checkers_hole&
checkers_hole::jump (honey_hole h)
{
  int x, y, x1, y1;
  if (h == _No)
    {
      _No = CHECKERS_HOLE_ERROR;
      return *this;
    }
  h.get (x, y);
  get (x1, y1);
  x -= x1;
  y -= y1;
  if ((x * y != 0) && (x != y))
    {
      _No = CHECKERS_HOLE_ERROR;
      return *this;
    }
  x1 += 2 * x;
  y1 += 2 * y;
  honey_hole::set (x1, y1);
  if (!in())
    _No = CHECKERS_HOLE_ERROR;
  return *this;
}

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -