Skip to content
Traffic Simulator for Microsoft Makecode Editor
TypeScript CSS HTML
Branch: master
Clone or download
Latest commit 8f58b52 Dec 14, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Documents
cmds Files Upload Sep 27, 2017
docs loader logo changes Dec 5, 2017
libs intersection blocks rearranged Dec 5, 2017
screenshots Readme updated Dec 14, 2017
sim
theme ui & files modified Dec 5, 2017
.gitattributes Files Upload Sep 27, 2017
.gitignore Files Upload Sep 27, 2017
.gitmodules Removing submodule and obsolete code Oct 17, 2017
.travis.yml Files Upload Sep 27, 2017
LICENSE Files Upload Sep 27, 2017
README.md readme updated Dec 14, 2017
package-lock.json ui & files modified Dec 5, 2017
package.json Merge foo branch to master (#9) Dec 3, 2017
pxtarget.json logos change Dec 5, 2017
targetconfig.json Update for pxt + example skeleton (#8) Dec 1, 2017
typings.json integrated library into simulator.ts Oct 30, 2017

README.md

Coraffic - Cornell MPS Program Team

Traffic Simulator for Microsoft Makecode Editor

This program allows you to interact with traffic simulation using PXT (Microsoft Programming Experience Toolkit)

Preview of the Editor

Editor Example

  • Preview of the Example

  • Code Example

    Beat the Traffic - Event

    // Create event blocks
    events.onCarInter(0, function () {
        intersections.setDirAtInter(TLDir.NS, 0)
        intersections.setDirAtInter(TLDir.EW, 1)
        intersections.setDirAtInter(TLDir.NS, 2)
    })
    

    Beat the Traffic - Intersections

    /* Create controls of intersections' actions */
    
    // Create a forever loop
    loops.forever(function () {
      // Create a for loop for setting up the allowed directions to be North-South at all intersections
      for (let index = 0; index <= 7; index++) {
          intersections.setDirAtInter(TLDir.NS, index)
      }
    })
    

    Beat the Traffic - Status

    /* Use Status blocks to check conditions for controlling intersections
    
    loops.forever(function () {
      for (let index = 0; index <= 7; index++) {
          // Check number of cars waiting for North-South at intersection (index)
          if (status.getCarsWait(TLDir.NS, index) > 1) {
              intersections.setDirAtInter(TLDir.NS, index)
          } 
          // Check number of cars waiting for East-West at intersection (index)
          else if (status.getCarsWait(TLDir.EW, index) >= 1) {
              intersections.setDirAtInter(TLDir.EW, index)
          } 
          // Check allowed direction at intersection (index)
          else if (status.getDirection(index) == status.locParam(TLDir.NS)) {
              intersections.setDirAtInter(TLDir.EW, index)
          } 
          // Check how long has the allowed direction been set at a random intersection
          else if (status.getDuration(status.randIndex()) >= 2) {
              intersections.setDirAtInter(TLDir.NS, status.randIndex())
          }
      }
    })
    

Running Locally

Set up

  • Install node.js

  • Install PXT command line

    npm install -g pxt
    
  • Install the dependencies

    npm install
    

Running the local server

  • After you're done, simple run this command to open a local web server:

    pxt serve
    
  • Updating the tools

    pxt update
    

More

More instructions at https://github.com/Microsoft/pxt#running-a-target-from-localhost

You can’t perform that action at this time.