File: group.h

package info (click to toggle)
galois 0.6-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 948 kB
  • sloc: cpp: 4,075; xml: 2,325; makefile: 146
file content (111 lines) | stat: -rw-r--r-- 3,915 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* group.h -- spatial groups for falling block game.  -*- C++ -*-
   Copyright (C) 2011-2015 Gerardo Ballabio

   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 3 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, see <http://www.gnu.org/licenses/>. */

#ifndef __GROUP_
#define __GROUP_

#include <vector>
#include <gtkmm.h>
#include "grid.h"

struct block
{
  std::vector<grid<bool> > shape, blocker;
  std::vector<int> rotate, reflect;
};

std::vector<block> random_blocks(const std::vector<block> &v, int n);

// virtual base class
class group
{
  // abstract interface
private:
  virtual int size() const = 0;
  virtual int rotations() const = 0;
  virtual int rotate(int n, int m) const = 0;
  virtual int reflect(int n) const = 0;
  virtual int type(const coords &c) const = 0;
  virtual std::vector<coords> neighbors(const coords &c) const = 0;
  virtual std::vector<coords> blockers(const coords &c) const = 0;
  virtual grid<bool> transform(const grid<bool> &g, int n) const = 0;
  virtual grid<bool> center(const grid<bool> &g) const = 0;
public:
  virtual bool is_3d() const = 0;
  virtual int blockset_max() const = 0; // values determined empirically

  // game
  virtual coords left(const coords &c) const = 0;
  virtual coords right(const coords &c) const = 0;
  virtual coords front(const coords &c) const = 0;
  virtual coords back(const coords &c) const = 0;
  virtual coords down(const coords &c) const = 0;
  virtual grid<int> make_board(int width, int depth = 1) const = 0;
  virtual std::vector<int> check_lines(grid<int> &g, int n) const = 0;
  virtual void color_line(grid<int> &g, int n, int color) const = 0;
  virtual void remove_line(grid<int> &g, int n) const = 0;

  // drawing methods
  virtual Gdk::Rectangle block_size(const grid<bool> &b, int size) const = 0;
  virtual Gdk::Rectangle board_size(int size, int rows, int cols,
				    int layers) const = 0;
  virtual void draw_brick(Cairo::RefPtr<Cairo::Context> context,
			  const coords &c, const Gdk::RGBA &color,
			  int size) const = 0;
  virtual void draw_shadow(Cairo::RefPtr<Cairo::Context> context,
			   const coords &c, const Gdk::RGBA &color,
			   int size) const = 0;
  virtual void draw_board(Cairo::RefPtr<Cairo::Context> context,
			  int rows, int cols, int layers, int size) const = 0;

  virtual ~group() { }

  // generic methods
private:
  grid<bool> augmentation_set(const grid<bool> &g) const;
  std::vector<grid<bool> > augment_grid(const grid<bool> &g) const;
  grid<bool> blockers_set(const grid<bool> &g) const;
  block make_block(const grid<bool> &g) const;
public:
  std::vector<block> augment_blocks(const std::vector<block> &v,
				    int x0 = 0, int z0 = 0,
				    int cols = 1, int layers = 1) const;
};

class group_2d : public group
{
private:
  virtual int rotations() const { return 1; }
  virtual coords front(const coords &c) const { return c; }
  virtual coords back(const coords &c) const { return c; }
public:
  virtual bool is_3d() const { return false; }
};

class group_3d : public group
{
private:
  virtual int rotations() const { return 3; }
public:
  virtual bool is_3d() const { return true; }
  virtual void draw_board_front(Cairo::RefPtr<Cairo::Context> context,
				int rows, int cols, int layers,
				int size) const = 0;
  virtual void draw_plane(Cairo::RefPtr<Cairo::Context> context,
			  int y, int cols, int layers, int size) const = 0;
};

#endif /* __GROUP_ */