-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A lot of small quality-of-life improvements to make it more like a playable game! [ADDED] - Optional pointer to an element (used in selection sort and quicksort) - Swapping animation for all sorts and sorting animation for merge sort - Persistent high score with moves-per-second tier ranking system - Configurable simulation size and speed - Quicksort (using Lomuto partition scheme) [CHANGED] - Replaced useless end screen with a view of sorted array
- Loading branch information
Showing
29 changed files
with
649 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
name: Bug report | ||
about: Create a report to help us improve | ||
title: '' | ||
labels: bug | ||
assignees: '' | ||
|
||
--- | ||
|
||
**Describe the bug** | ||
A clear and concise description of what the bug is. | ||
|
||
**To Reproduce** | ||
Steps to reproduce the behavior: | ||
1. Go to '...' | ||
2. Click on '....' | ||
3. Scroll down to '....' | ||
4. See error | ||
|
||
**Expected behavior** | ||
A clear and concise description of what you expected to happen. | ||
|
||
**Screenshots** | ||
If applicable, add screenshots to help explain your problem. | ||
|
||
**Desktop (please complete the following information):** | ||
- OS: [e.g. iOS] | ||
- Browser [e.g. chrome, safari] | ||
- Version [e.g. 22] | ||
|
||
**Smartphone (please complete the following information):** | ||
- Device: [e.g. iPhone6] | ||
- OS: [e.g. iOS8.1] | ||
- Browser [e.g. stock browser, safari] | ||
- Version [e.g. 22] | ||
|
||
**Additional context** | ||
Add any other context about the problem here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
name: Feature request | ||
about: Suggest an idea for this project | ||
title: '' | ||
labels: enhancement | ||
assignees: '' | ||
|
||
--- | ||
|
||
**Is your feature request related to a problem? Please describe.** | ||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] | ||
|
||
**Describe the solution you'd like** | ||
A clear and concise description of what you want to happen. | ||
|
||
**Describe alternatives you've considered** | ||
A clear and concise description of any alternative solutions or features you've considered. | ||
|
||
**Additional context** | ||
Add any other context or screenshots about the feature request here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
As I would like to submit this project to the Congressional App | ||
Challenge, I unfortunately cannot accept contributions until Monday, | ||
October 19th, 2020 at the earliest. Kindly hold any issues and pull | ||
requests until then. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,35 @@ | ||
# Human Computer Simulator | ||
*Human Computer Simulator* is a game where you get to become your | ||
favorite algorithm and or data structure. | ||
|
||
# Screenshots | ||
![Level Select](assets/levels.png) | ||
|
||
# Download | ||
This software is in an alpha stage of development and I do not plan on | ||
releasing ready-to-run builds until a stable v1.0 release. However, it | ||
is very easy to run it yourself. Just grab the free and open source | ||
[Godot game engine](https://godotengine.org), import the `project.godot` | ||
file, and hit the play button. | ||
<br /> | ||
<p align="center"> | ||
<img src="assets/icon.png" alt="Logo" width="80" height="80"> | ||
|
||
<h1 align="center">Human Computer Simulator</h1> | ||
|
||
<p align="center"> | ||
A game where you get to become your favorite algorithm or data structure! | ||
<br /> | ||
<a href="https://github.com/DanielZTing/human-computer-simulator/issues/new?template=bug_report.md">Report Bug</a> | ||
· | ||
<a href="https://github.com/DanielZTing/human-computer-simulator/issues/new?template=feature_request.md">Request Feature</a> | ||
</p> | ||
</p> | ||
|
||
## Table of Contents | ||
|
||
* [About the Project](#about-the-project) | ||
* [Getting Started](#getting-started) | ||
|
||
## About The Project | ||
|
||
![Level select screen](assets/levels.png) | ||
|
||
You may have come across the famous [15 Sorting Algorithms in 6 Minutes](https://www.youtube.com/watch?v=kPRA0W1kECg) video by [Timo Bingoman](https://github.com/bingmann) at some point in your computer science career. There is currently no shortage of neat visualizations of all kinds of algorithms, but what if you could become the algorithm itself? | ||
|
||
In *Human Computer Simulator*, you control an algorithm operating on some data structure. Right now, the game is limited to sorting arrays. The end vision is to have a library of interactive, playable levels on anything from a search on a binary tree to Dijkstra's shortest path on a graph. | ||
|
||
It's written using the Godot game engine and licensed with [almost no restrictions](LICENSE.txt). Use it to make a lecture a bit more interesting, review for an assignment, or just kill time. Hope you enjoy. | ||
|
||
## Getting Started | ||
|
||
This software is in an alpha stage of development and I do not plan on releasing ready-to-run builds until a stable v1.0 release. However, it is very easy to run and hack the source code yourself. Just grab the lightweight free and open source [Godot game engine](https://godotengine.org/download), import the `project.godot` file, and hit the play button. | ||
|
||
A demo version (large download warning: ~20 MB) is available on this repository's [Github Pages](https://danielzting.github.io/human-computer-simulator). It requires a desktop browser with support for WebAssembly and WebGL; mobile is not currently supported. Since this is still in alpha, some things might be dumb, make no sense whatsoever, or just break outright. I welcome any feedback you may have. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
class_name QuickSort | ||
extends ComparisonSort | ||
|
||
const NAME = "QUICKSORT" | ||
const ABOUT = """ | ||
Quicksort designates the last element as the pivot and puts everything | ||
less than the pivot before it and everything greater after it. This | ||
partitioning is done by iterating through the array while keeping track | ||
of a pointer initially set to the first element. Every time an element | ||
less than the pivot is encountered, it is swapped with the pointed | ||
element and the pointer moves forward. At the end, the pointer and pivot | ||
are swapped, and the process is repeated on the left and right halves. | ||
""" | ||
const CONTROLS = """ | ||
If the highlighted element is less than the pivot or the pivot has been | ||
reached, press LEFT ARROW to swap it with the pointer. Otherwise, press | ||
RIGHT ARROW to move on. | ||
""" | ||
|
||
const ACTIONS = { | ||
"SWAP": "Left", | ||
"CONTINUE": "Right", | ||
} | ||
var _index = 0 | ||
var _pointer = 0 | ||
# Bookkeep simulated recursion with a binary tree of subarray bounds | ||
var _stack = BinaryTreeModel.new(Vector2(0, array.size - 1)) | ||
|
||
func _init(array).(array): | ||
pass | ||
|
||
func next(action): | ||
if _index == _pivot(): | ||
if action != null and action != ACTIONS.SWAP: | ||
return emit_signal("mistake") | ||
array.swap(_index, _pointer) | ||
if _pointer - _begin() > 1: | ||
_stack.left = BinaryTreeModel.new(Vector2(_begin(), _pointer - 1)) | ||
_stack = _stack.left | ||
elif _pivot() - _pointer > 1: | ||
_stack.right = BinaryTreeModel.new(Vector2(_pointer + 1, _pivot())) | ||
_stack = _stack.right | ||
else: | ||
while (_stack.parent.right != null | ||
or _stack.parent.left.value.y + 2 >= _stack.parent.value.y): | ||
_stack = _stack.parent | ||
if _stack.parent == null: | ||
return emit_signal("done") | ||
_stack.parent.right = BinaryTreeModel.new(Vector2( | ||
_stack.parent.left.value.y + 2, _stack.parent.value.y)) | ||
_stack = _stack.parent.right | ||
_index = _begin() | ||
_pointer = _index | ||
elif array.at(_index) < array.at(_pivot()): | ||
if action != null and action != ACTIONS.SWAP: | ||
return emit_signal("mistake") | ||
array.swap(_index, _pointer) | ||
_index += 1 | ||
_pointer += 1 | ||
else: | ||
if action != null and action != ACTIONS.CONTINUE: | ||
return emit_signal("mistake") | ||
_index += 1 | ||
|
||
func _begin(): | ||
return _stack.value.x | ||
|
||
func _pivot(): | ||
return _stack.value.y | ||
|
||
func get_effect(i): | ||
if i < _begin() or i > _pivot(): | ||
return EFFECTS.DIMMED | ||
if i == _index or i == _pivot(): | ||
return EFFECTS.HIGHLIGHTED | ||
return EFFECTS.NONE | ||
|
||
func get_pointer(): | ||
return _pointer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.