Skip to content

Instantly share code, notes, and snippets.

View lfaoro's full-sized avatar
💭
3NG1N33R

Leonardo Faoro lfaoro

💭
3NG1N33R
View GitHub Profile
@lfaoro
lfaoro / content
Created September 10, 2014 12:09
func trueOrFalse(col: Int, _ row: Int) -> Bool {
var position = piecePosition(col, row)
for (cellName, cellStatus) in cellState {
if let cellStatus = cellStatus {
if cellName == position{
println("There is a piece on the \(position) square!")
var match = true
}
}
}
@lfaoro
lfaoro / content
Created September 10, 2014 12:13
//
// ChessBoard.swift
// iLichess Mac
//
// Created by Leonard Faoro on 07/09/2014.
// Copyright (c) 2014 Lichess.org. All rights reserved.
//
import Cocoa
import Swift
@lfaoro
lfaoro / content
Created September 10, 2014 17:49
x1) an enum called Shape with all possible shapes
x2) an enum called Colour with all (two) possible colours
x3) a struct called Piece that has a Shape and a Colour
x4) a dictionary storing the 64 squares of the chessboard. Each square has either a Piece or nil. Use an optional type for the values and that position(column row) function for the keys
x5) a dictionary representing the initial configuration of a board
/6) a dictionary representing this configuration:
http://upload.wikimedia.org/wikipedia/commons/a/af/Chess_tablebase_query.png
x7) a function that lists all the pieces in the initial configuration of a board
x9) a function that lists all the black pieces in the configuration of step 6
x8) a function that lists all the white pieces in the configuration of step 6 along with their positions
@lfaoro
lfaoro / content
Created September 10, 2014 20:14
{"game":{"id":"ufJVPEUz","variant":"standard","speed":"unlimited","perf":"classical","rated":false,"fen":"rnbqkbnr/pp2pppp/2p5/3p4/4P3/2N5/PPPP1PPP/R1BQKBNR w KQkq - 0 3","moves":"e4 d5 Nc3 c6","started":true,"finished":false,"clock":false,"clockRunning":false,"player":"white","turns":4,"startedAtTurn":0,"lastMove":"c7c6"},"clock":null,"player":{"id":"2nML","color":"white","version":38,"spectator":false},"opponent":{"color":"black","ai":1},"url":{"pov":"/ufJVPEUz2nML","socket":"/ufJVPEUz2nML/socket/v1","end":"/ufJVPEUz2nML/end","table":"/ufJVPEUz2nML/table"},"pref":{"animationDelay":240,"autoQueen":2,"autoThreefold":2,"clockTenths":true,"clockBar":true,"enablePremove":true},"chat":null,"possibleMoves":{"c3":"b5d5a4e2b1","b2":"b3b4","e1":"e2","g2":"g3g4","f1":"e2d3c4b5a6","g1":"f3h3e2","e4":"e5d5","h2":"h3h4","d2":"d3d4","a1":"b1","d1":"e2f3g4h5","a2":"a3a4","f2":"f3f4"},"tournamentId":null,"poolId":null
@lfaoro
lfaoro / content
Created September 10, 2014 21:36
func piecePosition(row: Int, column: Int) -> String {
let letters = ["a","b","c","d","e","f","g","h"]
let numbers = ["1","2","3","4","5","6","7","8"]
var atRow = letters[row]
var atColumn = numbers[column]
let piecePosition = atRow + atColumn
return piecePosition
}
@lfaoro
lfaoro / content
Created September 10, 2014 21:44
class Game {
let pieces = ["King": 1, "Queen": 1, "Bishop": 2, "Knight": 2, "Rook": 2, "Pawn": 8]()}
@lfaoro
lfaoro / content
Created September 11, 2014 19:44
import Cocoa
class BoardViewController: NSViewController {
view.addSubview
@lfaoro
lfaoro / content
Created September 12, 2014 11:03
let FEN:String = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR"
var row = 0
var col = 0
for c in FEN {
if c == "/" {col++; row = 0}
if c != "8" && c != "/" {
let img:String = String(c)
// var pieceImg = NSImage(named: img)
var notation = piecePosition(row, col)
row++
@lfaoro
lfaoro / content
Created September 12, 2014 13:50
var position = piecePosition(row, col)
var pos = squareID[position]
if let pos = pos! {
let img:String = String(c)
var pieceImg = NSImageView(frame: CGRect(x: pos.0, y: pos.1, width: squareDimension, height: squareDimension))
pieceImg.image = NSImage(named: img)
}
@lfaoro
lfaoro / content
Created September 12, 2014 15:52
var row = 0
var col = 7
for c in FEN {
if c == " " {continue}
if c == "w" {activePlayer = "white";break}
if c == "/" {col--; row = 0}
if c != "8" && c != "/" {
var position = piecePosition(row, col)
var pos = squareID[position]
if let pos = pos {