I like this one, although I don't quite understand how to play it
This might be useful to kids to learn algorithms, but for programming students...? they would have to be pretty darn stupid to use games to understand algorithms lol.
Also noticed a... glitch? that "Resume Game" is greyed out, but when you press "New game", "resume game" lights up.
You don't play the game in order to learn programming. You program the unfinished game in order to learn programming.
The students get this project with dummy implementations of the algorithms and datastructures. The game won't work properly when they get it. The trucks won't find the paths, the factories won't produce, the pipes won't transport resources. This only works after the students implemented their algorithms and datastructures.
I.e. a student will get this:
package logic.sorting;
import java.util.Comparator;
/**
* A sorter for arrays of type T[].
*
* @author Deque
*
* @param <T> the type of the elements that are sorted
*/
public interface Sorter<T> {
/**
* Sorts the array in ascending order using the comparator to compare array
* elements and the swapper to change the position of array elements.
*
* (Doing so in another way won't work. Not the resulting array is used, but
* the steps you take. Steps won't be recognized if you don't use swapper
* and comparator.)
*
* @param array
* @param comparator
* @param swapper
*/
public void sort(T[] array, Comparator<T> comparator, Swapper<T> swapper);
}
And might implement a BubbleSort:
package logic.sorting;
import java.util.Comparator;
/**
*
* @author Deque
*
* @param <T>
*/
public class BubbleSort<T> implements Sorter<T> {
@Override
public void sort(T[] array, Comparator<T> comparator, Swapper<T> swapper) {
boolean swapped;
do {
swapped = false;
for (int i = 1; i < array.length; i++) {
if (comparator.compare(array[i - 1], array[i]) > 0) {
array = swapper.swap(array, i - 1, i);
swapped = true;
}
}
} while (swapped);
}
}
Now if the student runs the project, the factories will produce.
Note that the student doesn't need to know anything about the factory code or how the factory works. The interface is all they need.
But if they want to, they can see how the algorithms work together.
It's a lot code indeed. cloc tells me I have written 5244 lines of code. I needed a whole semester to write this.
---------------------------------------------------------
About the glitch: I know this one. The game isn't finished yet and I am working on it.