Skip to content

Instantly share code, notes, and snippets.

View jwbuurlage's full-sized avatar

Jan-Willem Buurlage jwbuurlage

View GitHub Profile
@jwbuurlage
jwbuurlage / gist:3739451
Created September 17, 2012 20:04
Voorbeeld AI
module SeaBattle
class AIPlayer < Player
def setup
@boatSet.each do |boat|
loop do
i = rand(10)
j = rand(10)
boat.moveTo(i, j)
boat.rotateTo(i + 1, j)
break if @board.valid? boat
class NetworkController
def initialize(addr, port)
socket = GCDAsyncSocket.alloc.initWithDelegate(self, delegateQueue:Dispatch::Queue.current.dispatch_object)
err_ptr = Pointer.new(:object)
if not socket.connectToHost(addr, onPort:port, error:err_ptr)
puts "doesn't work: #{err_ptr[0]}"
end
socket.writeData("data\n".dataUsingEncoding(NSASCIIStringEncoding), withTimeout:-1, tag:1)

Byn

Objective-C

Starry

Astronomy application with which you can view the current position of planets, constellations and stars and other celestial objects from any point on the earth at any given time.

@jwbuurlage
jwbuurlage / design_patterns.md
Created August 23, 2012 17:24
Design Patterns

DESIGN PATTERNS

Template

Abstract superclass, methods are overridden in subclasses

Strategy

@jwbuurlage
jwbuurlage / boat_raise.rb
Created August 22, 2012 18:21
Boats met raising errors
# ------------------------------------------------------------------------------
# dit is een proc
check = lambda do |i|
(i <= 5) # returned false als i > 5
end
# we callen de proc voor alle i in 1..6
@jwbuurlage
jwbuurlage / gist:3312587
Created August 10, 2012 08:24
Extract red color in OpenGL
glBlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
glUniformMatrix4fv(LOC_BASIC_MVP, 1, GL_FALSE, GLKMatrix4Identity.m);
glUniform4f(LOC_BASIC_COLOR, 1.0f, 0.0f, 0.0f, 1.0f);
glBindBuffer(GL_ARRAY_BUFFER, unit_square_vertex_buffer);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float),(GLvoid*)0);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
SRInterfaceController* interface = [[SRInterfaceController alloc] init];
SomeGLKViewController* glVC = [[SomeGLKViewController alloc] initWithNibName:nil bundle:nil];
starVC.preferredFramesPerSecond = 60;
[mainVC addChildViewController:interface];
[mainVC addChildViewController:glVC];
[[mainVC view] addSubview:[glVC view]];
[[mainVC view] addSubview:[interface view]];
@jwbuurlage
jwbuurlage / gist:3252098
Created August 3, 2012 22:18
Render loop
// relevant code before the call
// ...
glUseProgram(PROG_POINT);
glUniformMatrix4fv(LOC_POINT_MVP, 1, GL_FALSE, modelViewProjectionMatrix.m);
glUniform1i(LOC_POINT_TEXTURE, 0);
glUniform4f(LOC_POINT_COLOR, 1.0f, 1.0f, 1.0f, 1.0f);
glBindBuffer(GL_ARRAY_BUFFER, some_vertex_buffer);
glEnableVertexAttribArray(0);
module SeaBattle
class Board
def initialize
@grid = Array.new(100, 0)
end
def set_boat(i, j, o, length)
# o = orientation, 0 = right, 1 = down
if(o == 0)
for x in j...(j+length)
module TicTacToe
class Board
def initialize
@grid = Array.new(9, -1)
end
def move(square, player)
return false unless @grid[square] == -1
@grid[square] = player
end