This forum is in archive mode. You will not be able to post new content.

Author Topic: [Project] PipCo - Strategy Game to Learn Algorithms and Datastructures  (Read 915 times)

0 Members and 1 Guest are viewing this topic.

Offline Deque

  • P.I.N.N.
  • Global Moderator
  • Overlord
  • *
  • Posts: 1203
  • Cookies: 518
  • Programmer, Malware Analyst
    • View Profile
Hello EZ,

I want to introduce to you my ongoing project written in Java. I do this for my professor at university who teaches bachelor computer science students algorithms and datastructures.

Idea

The idea is to have an incomplete game. Certain datastructures and algorithms are left for the students to implement. Once they did this, the game will behave according to their implementation.
I made my own implementations of these algorithms to test the game. The following pictures and the download below will show you the complete game.

Game

The principle of the game by now is to transport red resources on the map by using pipes. Factories will produce when they get resources. The products are transported by trucks to the flag.
There is no real challenging component by now as the project is not finished yet.

Screenshots

Note: The graphics are not final and I am not a designer at all. I know that some parts look crappy.

Menu


Map preview


Game


Game won



Algorithms and Datastructures to implement

Sorting AlgorithmSorts the random array of bars under the factory, once sorted a truck will appear and transport the products to the flag
Shortest Path Used by trucks to find the flag
Maximum Flow Calculates the flow of resources in the pipes
Sorted List Highscores
Linked List Map preview
Map Dictionary to change the language in the menu
Graph Used by Maximum Flow and Shortest Path
Breath First Search Used by Maximum Flow algorithm

Download

This is the fully implemented game.

http://uppit.com/9763u2oau7t9/hcpipco.zip

Starting the game

This game should work for Windows, MacOS, Solaris and Linux. You need a Java Runtime >= 1.6.

Windows users run pipco.bat
Linux users run pipco.sh

Alternatively run on commandline:

Code: [Select]
java -Djava.library.path=./resources_lib/native/linux -jar resources.jar
Deque
« Last Edit: April 12, 2013, 09:36:40 PM by Deque »

Offline Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 6627
  • Cookies: 542
  • Fascist dictator
    • View Profile
    • My blog
I like this one, although I don't quite understand how to play it :P
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.

Offline 0poitr

  • Peasant
  • *
  • Posts: 149
  • Cookies: 64
    • View Profile
I like this one, although I don't quite understand how to play it :P
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.

I think it's more about learning/discovering where to apply what algorithm and use what data-structures rather than understanding the algorithm and data-structures themselves.
Games are in fact pretty complex if you think about the implementation details. So, It's a good exercise and boosts innovability (in a way).
Imagination is the first step towards Creation.

Offline Deque

  • P.I.N.N.
  • Global Moderator
  • Overlord
  • *
  • Posts: 1203
  • Cookies: 518
  • Programmer, Malware Analyst
    • View Profile
I like this one, although I don't quite understand how to play it :P
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:

Code: [Select]
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: [Select]
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.
« Last Edit: April 13, 2013, 02:26:09 PM by Deque »

Offline Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 6627
  • Cookies: 542
  • Fascist dictator
    • View Profile
    • My blog
Well in that case this does seem interesting. I'll wait until you finish it :)

 



Want to be here? Contact Ande, Factionwars or Kulverstukas on the forum or at IRC.