DU CODE Snake Competition
 
Loading...
Searching...
No Matches
grid.h
Go to the documentation of this file.
1
4
5#pragma once
6
7#include "cell.h"
8#include "lib/cells.h"
9#include "pos.h"
10#include <iostream>
11#include <optional>
12#include <vector>
13
22class Grid {
23public:
31 Grid(bool is_player_one, const int current_tick, const Cells &cells,
32 const std::vector<Pos> &player_one_segments,
33 const std::vector<Pos> &player_two_segments);
37
42 Cell get(int x, int y) const;
43
48 Cell get(Pos pos) const;
49
51 int get_height() const;
52
54 int get_width() const;
55
59 int get_current_tick() const;
60
62 std::vector<Pos> find_fruits() const;
63
65 Pos find_self_head() const;
66
69 std::vector<Pos> find_self_positions() const;
70
72 Pos find_other_head() const;
73
76 std::vector<Pos> find_other_positions() const;
77
78private:
79 const Cells &cells;
80 bool is_player_one;
81 const int current_tick;
82 const std::vector<Pos> &player_one_segments;
83 const std::vector<Pos> &player_two_segments;
84 std::vector<Pos> find(Cell cell) const;
85};
Cell
Represents every cell on a Grid. Cell is returned by Grid::get.
Definition cell.h:9
Represents the grid of cells containing snakes and fruits. Grid is used in the MyBot::think function ...
Definition grid.h:22
Pos find_other_head() const
Returns the head of the other snake.
Definition grid.cpp:42
std::vector< Pos > find_self_positions() const
Get the ordered positions of all your parts. The first element is the head.
Definition grid.cpp:51
int get_height() const
Returns the height of the grid.
Definition grid.cpp:25
int get_width() const
Returns the width of the grid.
Definition grid.cpp:28
std::vector< Pos > find_other_positions() const
Get the ordered positions of the other snake. The first element is their head.
Definition grid.cpp:60
int get_current_tick() const
Returns the current tick with 0 being the first tick and FINAL_TICK being the last....
Definition grid.cpp:30
std::vector< Pos > find_fruits() const
Returns all fruit as a std::vector<Pos>
Definition grid.cpp:32
Pos find_self_head() const
Get the position of your head.
Definition grid.cpp:34
Cell get(int x, int y) const
Returns a Cell at (x, y) or throws if x and y are invalid.
Definition grid.cpp:12
Pos represents a position on the Grid; the origin is bottom left.
Definition pos.h:9