Skip to content

Instantly share code, notes, and snippets.

@tgoossens
tgoossens / gist:4113588
Created November 19, 2012 20:13
3x3 puzzle representation
1 2 3
0 0 0
0 0 0
Rotate left
2 3 0
1 0 0
0 0 0
@tgoossens
tgoossens / gist:4124151
Created November 21, 2012 10:27
Evaulate Secure
private void createQueue() {
queue = new ArrayDeque<When<Predicate<RobotState>,Fn>>();
queue.push(when(isOnWhiteLine,driveLongBackward)); //if already on white line move backward
queue.push(when( and(isIdle, not(isOnWhiteLine)), driveForward)); //start driving forward
queue.push(when( and(isMoving, isOnWhiteLine), stopRobot)); //stop when white line is detected
@tgoossens
tgoossens / gist:4126640
Created November 21, 2012 18:18
whitelineproc
package procedure;
import model.Color;
import model.Direction;
import model.DrawRequest;
import model.DrawType;
import model.Position;
import model.RobotActivity;
import model.RobotState;
import model.Rotation;
@tgoossens
tgoossens / gist:4131595
Created November 22, 2012 15:02
mazeexplore quick fix
* Drives the robot in the requested direction. As always the direction is in the relative axis of the robot,
* instead of the absolute one.
* @param reqDir
*/
private void driveSectorLengthInDirection(Orientation reqDir) {
if(reqDir == currentOrientation.turnClockWise()){
getRobot().rotate(90, Rotation.CLOCKWISE);
}else if(reqDir == currentOrientation.turnAntiClockWise()){
getRobot().rotate(90, Rotation.COUNTERCLOCKWISE);
}else if(reqDir == currentOrientation.opposite() ) {
Name: V(i), i=1..6, domain: 0..9
Name: E(i), i=1..9, domain: 1..9
Constraint: V(i) \= V(j), range: i < j
Constraint: E(i) \= E(j), range: i < j
Constraint: E(i) = abs(V(b)-V(a)) /\ E(j) = abs(V(c)-V(d)) /\ E(k) = abs(V(e)-V(f)), range: i >= 0, i =< 3, a=i, b = (a mod 3) + 1, b <= 3 , j=i+3, c=a+3,d=b+3, k=i+6, e=a, f=d
@tgoossens
tgoossens / piece.clj
Created December 4, 2012 22:22
Board game
Idea
------
I'm redesigning last years project in java (course: OOP)
Long story short:
I have a "board" ,"robot" "item", "wall"
a board contains pieces at certain positions
@tgoossens
tgoossens / BTInitiator.java
Created February 14, 2013 11:19
TestClasses for BTProtocol of p&o project 2013. BTInitiator runs on the PC and initiaties the bluetoothconnection. And opens a DataInputStream CommTest (receiver) runs on NXT and waits for incoming connection. USAGE: 1) startup NXT with CommTest 2) Press Right arrow to let CommTest wait for bluetooth connection 3) Startup BTInitiator
import java.io.IOException;
import java.io.OutputStream;
import lejos.pc.comm.NXTComm;
import lejos.pc.comm.NXTCommException;
import lejos.pc.comm.NXTCommFactory;
import lejos.pc.comm.NXTInfo;
/*
* RUNS ON PC
@tgoossens
tgoossens / SampleInterface.java
Last active December 13, 2015 19:08
A specialised method that creates a mock object. When a mock object's method is invoked information about its arguments is written a string (in bytes) to the outputstream
package meta.nxt;
public interface SampleInterface {
public void singleint (int a);
public void twiceint (int a, int b);
@tgoossens
tgoossens / Person.java
Last active December 15, 2015 02:59
Immutable classes with public fields. because what the heck?
package p2;
/**
* Person with string address
*/
public final class Person{
public final String name;
public final String address; //addres defined in the same manner as person
public final JodaDate birthdate; //because java date suck
@tgoossens
tgoossens / aimd.clj
Created March 29, 2013 17:16
AIMD (Additive Increment Multiplicative Decrement) simulator for my assignment of Computer Networks. I used encanter to visualise the results. A possible extensions of this small piece of software would be to have the "maxbandwidth" to be variable over time so that the dynamic properties of AIMD can be studied.
(ns aimd.core
(:require [incanter.core :as ic]
[incanter.stats :as stats]
[incanter.charts :as charts]))
(defn increase-rate
"Additive incrementation of the rate of sender s with a factor n"
[n s]
(update-in s [:rate] + n))