RE: [Project] PipCo - Strategy Game to Learn Algorithms and Datastructures 04-12-2013, 08:52 PM
#3
(04-12-2013, 08:42 PM)Psycho_Coder Wrote: I just Love Algorithms and Data Structures , thank you , and its great that I can learn while playing .
Great Concept ... :ok:
You can't learn while playing.
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:
Code:
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:
Code:
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.
I am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.
Expressed feelings are just an attempt to simulate humans.
![[Image: 2YpkRjy.png]](http://i.imgur.com/2YpkRjy.png)

![[+]](https://sinister.li/images/modern/collapse_collapsed.png)