Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: tychon/turing_simulator
base: f43e808e0a
...
head fork: tychon/turing_simulator
compare: 4d13f4241f
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Showing with 37 additions and 6 deletions.
  1. +2 −1  index.html
  2. +22 −5 simulation.js
  3. +13 −0 style.css
View
3  index.html
@@ -1,6 +1,6 @@
<html>
<head>
- <title>Turing-Maschine</title>
+ <title>Turing machine</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script language="JavaScript" src="compiler.js"></script>
<script language="JavaScript" src="simulation.js"></script>
@@ -125,6 +125,7 @@
<a id="description_button" href="javascript:if(guiEnabled) openDescription()" class="button tabButton" style="margin-left:0px; border-top-left-radius:5px">Description</a>
<a id="simulation_button" href="javascript:if(guiEnabled) openSimulation()" class="button tabButton" style="background-color:lightblue">Simulation</a>
<a id="test_button" href="javascript:if(guiEnabled) openTest()" class="button tabButton" style="border-top-right-radius:5px">Test</a>
+ <a class="github_link" href="http://github.com/tychon/turing_simulator" style="float: right; text-align: right">This project on GitHub</a>
</div>
<div id="machine" style="min-width:300px; float:right"></div>
<div id="tabPane" style="float:left">
View
27 simulation.js
@@ -60,19 +60,36 @@ function sim_step(callback) {
if (parallel) {
sim.state = transition.dest
var oldpos = calculateTapePositions()
+ , box_size = +document.getElementById('tape_size_slider').value
, tape, newpos
for (var i = 0; i < sim.tapes.length; i++) {
tape = sim.tapes[i]
tape.content = setCharAt(tape.content, tape.head_pos, transition.write[i])
if (transition.move[i] == 'L') {
if (tape.head_pos == 0) {
- tape.content = machine.blank_symbol+tape.content
- oldpos[i] -= +document.getElementById('tape_size_slider').value
+ tape.content = machine.blank_symbol + tape.content
+ oldpos[i] -= box_size
+ } else {
+ if (tape.head_pos == tape.content.length-1
+ && tape.content[tape.head_pos] == machine.blank_symbol
+ && tape.content.length > 1) {
+ // shorten tape if it ends with blanks
+ tape.content = tape.content.substring(0, tape.content.length-1)
+ }
+ tape.head_pos --
}
- else tape.head_pos --
} else if (transition.move[i] == 'R') {
- if (tape.head_pos == tape.content.length-1) tape.content = tape.content+machine.blank_symbol
- tape.head_pos ++
+ if (tape.head_pos == 0
+ && tape.content[0] == machine.blank_symbol
+ && tape.content > 1) {
+ // shorten if it begins with blanks
+ tape.content = tape.content.substr(1)
+ oldpos[i] -= box_size
+ } else {
+ if (tape.head_pos == tape.content.length-1)
+ tape.content = tape.content + machine.blank_symbol
+ tape.head_pos ++
+ }
}
}
moveTapes(oldpos, calculateTapePositions(), total_time/2, function() {
View
13 style.css
@@ -32,6 +32,19 @@ a.tabButton:hover {
background-color: white;
}
+a.github_link, a.github_link:hover {
+ background-color: lightgreen;
+ border: 1px solid black;
+ border-radius: 5px;
+ padding-left: 5px;
+ padding-right: 5px;
+ color: black;
+ text-decoration: none;
+}
+a.github_link:hover {
+ background-color: pink;
+}
+
div.tab {
padding:5px;
background-color: lightgrey;

No commit comments for this range

Something went wrong with that request. Please try again.