Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

working on chess

  • Loading branch information...
commit 8879c3cfc2d7534b3d52d12f99a0acbb66287bb4 1 parent d6acbe0
Tim Felgentreff authored
View
17 examples_pk/chess/README
@@ -0,0 +1,17 @@
+P1 - setUp (returns 2.16.2.3.0 = 192bit = 6*32bit)
+ 2 -> B/W
+ 16 -> König,Dame,Turm1,Turm2,Läufer1,Läufer2,Springer1,Springer2,Bauer1-8
+ 2 -> Feld-X,Feld-Y
+P11 - setUpColor # sets up one color
+
+P2 - something there, that's yours? (3.0, 3.0, 2.16.2.3.0, 0)(int,int,int + (b/w)) -> (0/1)
+
+P4 - move that there (if you can)
+P41 - what is there? (3.0)
+ 001 -> Bauer
+ 010 -> Springer
+ 011 -> Läufer
+ 100 -> Turm
+ 101 -> Dame
+ 110 -> König
+P42 - can that move so?
View
21 examples_pk/chess/chess.rb
@@ -0,0 +1,21 @@
+require 'sinatra'
+require 'haml'
+require 'json'
+require 'pkchess'
+
+#use Rack::Auth::Basic do |username, password|
+# username == 'admin' && password == 'secret'
+#end
+
+get '/' do
+ haml :index, {}, :blah => 10
+end
+
+get '/select/:x/:y' do
+ PKChess.new.select(params[:x],params[:y]).to_json
+end
+
+get '/move/:x1/:y1/to/:x2/:y2' do
+ #"Set #{params[:x1]}@#{params[:y1]} to #{params[:x2]}@#{params[:y2]}"
+ true.to_json
+end
View
11 examples_pk/chess/logic/select.pk
@@ -0,0 +1,11 @@
+P2 (V0[:3.0],V1[:3.0],V2[:2.16.2.3.0],V3[:0]) => R0[:0]
+ V2[V3[:0]:16.2.3.0] => Z0[:16.2.3.0]
+ 0 => R0[:0]
+ W1(16) [
+ Z0[i:2.3.0] => Z1[:2.3.0]
+ Z1[0:3.0] = V0[:3.0] -> [
+ Z1[1:3.0] = V1[:3.0] -> 1 => R0[:0]
+ FIN
+ ]
+ ]
+END
View
5 examples_pk/chess/logic/setup.pk
@@ -0,0 +1,5 @@
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8 @@
+load 'select.rb'
+load 'setupColor.rb'
+load 'setup.rb'
+
+puts Plankalkuel.p11(1).to_i
+puts Plankalkuel.p11(0).to_i
+field=Plankalkuel.p1(0)
+puts Plankalkuel.p2(1,1,field,0).to_i
View
20 examples_pk/chess/pkchess.rb
@@ -0,0 +1,20 @@
+require 'pk2000'
+require 'logic/setupColor' # single Color setup, p11(0/1)
+require 'logic/setup' # complete setup, p1(0)
+require 'logic/select' # is_selectable_by_you? p2(0/1)
+
+class PKChess
+ include Plankalkuel
+
+ def initialize
+ @field = Plankalkuel.p1(0)
+ end
+
+ def select x,y
+ Plankalkuel.p2(x,y,@field,0).to_i > 0
+ end
+
+ def move x1,y1,x2,y2
+ true
+ end
+end
View
16 examples_pk/chess/public/chess.css
@@ -0,0 +1,16 @@
+.overlay {
+ color: #0ff;
+ opacity: 0.5;
+}
+
+.tile {
+ width: 50px;
+ height: 50px;
+ position: fixed;
+}
+
+.board {
+ margin-left: auto;
+ margin-right: auto;
+ margin-top: 100px;
+}
View
86 examples_pk/chess/public/chess.js
@@ -0,0 +1,86 @@
+
+$(function () {
+ showCheckerBoard(8,8);
+ showStones();
+})
+
+var tiles = [[],[],[],[],[],[],[],[]];
+var stones = [[],[],[],[],[],[],[],[]];
+var clicked = null;
+
+function tile(x,y) {
+ this.x = x;
+ this.y = y;
+ if ((Math.abs(x - y) % 2) == 1)
+ this.color = "#fa4";
+ else
+ this.color = "#c94";
+ o = $("<div class='tile'></div>")
+ .css("background", this.color)
+ .css("left", this.x*50+100)
+ .css("top", this.y*50+100);
+ $(o).click(function() {
+ click(this,x,y) });
+ $(".board").append(o);
+ return o;
+}
+
+function stone(name,x,y) {
+ o = $("<div>"+name+"</div>");
+ o.css("position", "absolute");
+ $(".board").append(o);
+ stones[x][y] = o;
+ set_stone(x,y,x,y);
+}
+
+function move(x1,y1,x2,y2) {
+ $.getJSON("/move/"+x1+"/"+y1+"/to/"+x2+"/"+y2,
+ function(data) {
+ if (data) {
+ set_stone(x1,y1,x2,y2);
+ };
+ });
+}
+
+function click(o,x,y) {
+ $.getJSON("/select/"+x+"/"+y, function(data) {
+ if (clicked == null) {
+ if (data) {
+ clicked = [x,y];
+ $(o).addClass('overlay');
+ }
+ } else {
+ move(clicked[0],clicked[1],x,y);
+ clicked = null;
+ $(".overlay").removeClass('overlay');
+ }});
+}
+
+function set_stone(x,y,x1,y1) {
+ pos = tiles[x1][y1].position();
+ o = stones[x][y]
+ o.animate({
+ left: pos.left+"px",
+ top: pos.top+"px" }, 500);
+ stones[x][y] = null;
+ stones[x1][y1] = o;
+}
+
+function showCheckerBoard(x, y) {
+ for (i = 0; i < x; i++) {
+ for (j = 0; j < y; j++) {
+ tiles[i][j] = new tile(i,j);
+ }
+ }
+}
+
+function showStones() {
+ for (i = 0; i < 8; i++) {
+ stone("B_b", i, 1);
+ stone("B_w", i, 6);
+ }
+ stone("T_w", 0, 7);
+ stone("T_w", 7, 7);
+ stone("T_b", 0, 0);
+ stone("T_b", 7, 0);
+}
View
6 examples_pk/chess/views/index.haml
@@ -0,0 +1,6 @@
+%script{:src => "http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js", :type => "text/javascript"}
+%script{:src => "./chess.js", :type => "text/javascript"}
+%link{:rel => 'stylesheet', :href => "./chess.css"}
+#headline
+ %h2 Welcome to the PK2000 powered Chess-challenge!
+ .board
Please sign in to comment.
Something went wrong with that request. Please try again.