This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // ChessBoard.swift | |
| // iLichess Mac | |
| // | |
| // Created by Leonard Faoro on 07/09/2014. | |
| // Copyright (c) 2014 Lichess.org. All rights reserved. | |
| // | |
| import Cocoa | |
| import Swift |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {"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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Game { | |
| let pieces = ["King": 1, "Queen": 1, "Bishop": 2, "Knight": 2, "Rook": 2, "Pawn": 8]()} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Cocoa | |
| class BoardViewController: NSViewController { | |
| view.addSubview | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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++ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 { |