ScummVM API documentation
circuitpuzzle.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef VCRUISE_CIRCUITPUZZLE_H
23 #define VCRUISE_CIRCUITPUZZLE_H
24 
25 #include "common/array.h"
26 #include "common/random.h"
27 #include "common/rect.h"
28 
29 namespace Common {
30 
31 class RandomSource;
32 
33 } // End of namespace Common
34 
35 namespace VCruise {
36 
37 struct CircuitPuzzleAIEvaluator;
38 class CircuitPuzzleVisitedSet;
39 
41 public:
42  explicit CircuitPuzzle(int layout);
43 
44  static const uint kBoardWidth = 6;
45  static const uint kBoardHeight = 5;
46 
47  enum CellDirection {
48  kCellDirectionRight,
49  kCellDirectionDown,
50  };
51 
52  enum Conclusion {
53  kConclusionNone,
54  kConclusionPlayerWon,
55  kConclusionPlayerLost,
56  };
57 
58  struct CellRectSpec {
59  Common::Rect _rightLinkRect;
60  Common::Rect _downLinkRect;
61  Common::Rect _rightBarrierRect;
62  Common::Rect _downBarrierRect;
63  };
64 
65  // Returns true if the AI can act, if it can then the actions are produced
66  bool executeAIAction(Common::RandomSource &randomSource, Common::Point &outCoord, CellDirection &outBlockDirection);
67 
68  void addLink(const Common::Point &coord, CellDirection direction);
69 
70  Conclusion checkConclusion() const;
71 
72  const CellRectSpec *getCellRectSpec(const Common::Point &coord) const;
73  bool isCellDownLinkOpen(const Common::Point &coord) const;
74  bool isCellRightLinkOpen(const Common::Point &coord) const;
75 
76 private:
77  enum LinkState {
78  kLinkStateOpen,
79  kLinkStateConnected,
80  kLinkStateBlocked,
81  };
82 
83  enum Direction {
84  kDirectionUp,
85  KDirectionDown,
86  kDirectionLeft,
87  kDirectionRight,
88 
89  kDirectionCount,
90  };
91 
92  struct CellState {
93  CellState();
94 
95  LinkState _downLink;
96  LinkState _rightLink;
97  };
98 
99  struct Action {
100  Action();
101 
102  Common::Point _point;
103  CellDirection _direction;
104  };
105 
106  static Common::Point getConnectedPoint(const Common::Point &coord, Direction direction);
107  LinkState *getConnectionState(const Common::Point &coord, Direction direction);
108  const LinkState *getConnectionState(const Common::Point &coord, Direction direction) const;
109  static bool isPositionValid(const Common::Point &coord);
110 
111  void computeStepsToReach(CircuitPuzzleAIEvaluator &evaluator) const;
112  void floodFillLinks(Common::Point *pointsList, uint &listSize, CircuitPuzzleVisitedSet &visitedSet) const;
113 
114  static void validateCoord(const Common::Point &coord);
115 
116  CellState _cells[kBoardWidth][kBoardHeight];
117  CellRectSpec _cellRectSpecs[kBoardWidth][kBoardHeight];
118  Common::Point _startPoint;
119  Common::Point _goalPoint;
120 
121  bool _havePreviousAction;
122  Action _previousAction;
123 };
124 
125 } // End of namespace VCruise
126 
127 #endif
Definition: random.h:44
Definition: rect.h:144
Definition: circuitpuzzle.h:58
Definition: ad2044_items.h:27
Definition: algorithm.h:29
Definition: rect.h:45
Definition: circuitpuzzle.h:40