I apologize in advance for the pseudo-code. I haven't touched java (or any other language) in four years. I'm an old school VB6 programmer
The board was a HashSet of points and the pieces were HashSets of points
whenever a piece was rotated or moved, I did something like this:
board.containsAll(gamePiece) - If it returned false, the piece was going off the board - and the move wasn't allowed
To check for collisions between pieces when they moved or rotated, I did something like this:
tempPiece = new HashSet<Point>
tempPiece = gamePiece1.retainAll(gamePiece2) -tempPiece contains intersection between pieces
If tempPiece.size > 0 then the pieces overlapped - thus the move was not allowed
It would be nice to have an implementation of hashset that performs the set-algebraic operations. I know some of the methods are from collection.
From
http://docs.oracle.com/javase/tutorial/collections/interfaces/set.html
Bulk operations are particularly well suited to Sets; when applied, they perform standard set-algebraic operations. Suppose s1 and s2 are sets. Here's what bulk operations do:
- s1.containsAll(s2) — returns true if s2 is a subset of s1. (s2 is a subset of s1 if set s1 contains all of the elements in s2.)
- s1.addAll(s2) — transforms s1 into the union of s1 and s2. (The union of two sets is the set containing all of the elements contained in either set.)
- s1.retainAll(s2) — transforms s1 into the intersection of s1 and s2. (The intersection of two sets is the set containing only the elements common to both sets.)
- s1.removeAll(s2) — transforms s1 into the (asymmetric) set difference of s1 and s2. (For example, the set difference of s1 minus s2 is the set containing all of the elements found in s1 but not in s2.)
It would be nice to have a hashset with these operations for the community to use. I will be writing a tetris game as a learning exercise and would like to use sets to do so.
What is the best way to implement a hashset or equivalent? Is it possible to wrap the java hashset or would I have to implement the methods in b4a using a map?
Thanks for your patience.