package ch.zhaw.hexboard; import java.awt.Point; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; /*** *
* This class represents a simple generic hexagonal game board. *
*The game board uses a fixed coordinate system which is structured as follows:
* ** 0 1 2 3 4 5 6 7 8 * | | | | | | | | | ... * * 0---- C C C C C * \ / \ / \ / \ / \ * 1---- C C C C C * * 2---- F | F | F | F | F | ... * * 3---- C C C C C * / \ / \ / \ / \ / * 4---- C C C C C * * 5---- | F | F | F | F | F ... * * 6---- C C C C C * \ / \ / \ / \ / \ * 7---- C C C C C * * ... ** *
* Fields F and corners C can be retrieved * using their coordinates ({@link java.awt.Point}) on the board. Edges can be * retrieved using the coordinates of the two corners they connect. *
* ** When created, the board is empty (no fields added). To add fields, the * #{@link #addField(Point, Object)} function can be used. Edges and corners are * automatically created when adding a field. They cannot be created/removed * individually. When adding a field, edges and corners that were already * created, e.g., because adding an adjacent field already created them, are * left untouched. *
* ** Fields, edges and corners can store an object of the type of the * corresponding type parameter each. *
* ** Furthermore, the hexagonal game board can store six additional objects, so * called annotations, for each field. These objects are identified by the * coordinates of the field and the corner. Hence, they can be thought of being * located between the center and the respective corner. Or in other words, * their positions correspond to the positions N, NW, SW, NE, NW, SE and NE in * the below visualization of a field. *
* ** SW (C) SE * / N \ * (C) NW NE (C) * | F | * | | * (C) SW SE (C) * \ S / * NW (C) NE ** * @param
* If the specified corner is not a corner or none of the fields that touch this * corner have a non-null data element, an empty list is returned. *
* @param corner the location of the corner * @return the list with the (non-null) field data */ public List* Each corner has three direct neighbors, except corners that are located at * the border of the game board. *
* @param center the location of the corner for which to return the direct * neighbors * @return list with non-null corner data elements */ public List* Each corner has three edges connecting to it, except edges that are located * at the border of the game board. *
* @param corner corner for which to get the edges * @return list with non-null edge data elements of edges connecting to the * specified edge */ public List