stevebarnegren / swiftchess Goto Github PK
View Code? Open in Web Editor NEWChess engine and AI written in Swift
License: MIT License
Chess engine and AI written in Swift
License: MIT License
First of all, your project is really impressive. Thank you for sharing it.
Secondly, if I wanted to add a reset entire game feature to the GameViewController how would you recommend going about that?
I've tried a few different things but I think I am quite close now, but can't seem to figure out why it's not working.
I decided to use your persistence feature to reset the game. When the game is initially set I saved the dictionaryRepresentation of the game in a variable, so that when I reset the game I could do game = ChessGame(dictionary: startGameRepresentation)
, but that did not work. So i decided to reinitialize the game with a human and AI Player (the only scenario I want) and set the current player to the human player.
After that I remove all the pieces from the board and then setup the game again with the code that you've written in your viewDidLoad(). I then use the code you set up in viewDidLayoutSubviews to layout the pieces, but once that happens I cannot move any pieces. I can click on a piece and the square behind it gets highlighted in red, but I cannot then move the piece.
The problem I'm facing now is that guard let player = game.currentPlayer as? Human else { return }
always returns in the touchedSquareAtIndex
delegate function
My current code is as follows
fileprivate func setupGame() { //Copy of your viewDidLoad code
// Add initial piece views
for location in BoardLocation.all {
guard let piece = game.board.getPiece(at: location) else {
continue
}
addPieceView(at: location.x, y: location.y, piece: piece)
}
// Activity Indicator
activityIndicator.hidesWhenStopped = true
// Update castle buttons visibility
updateCastleButtonsVisibility()
}
func reset() {
let whitePlayer = Human(color: .white)
let blackPlayer = AIPlayer(color: .black, configuration: AIConfiguration(difficulty: gameDifficulty ?? AIConfiguration.Difficulty.medium))
game = ChessGame(firstPlayer: whitePlayer, secondPlayer: blackPlayer)
game.currentPlayer = whitePlayer
boardView.subviews.forEach { (v) in
v.removeFromSuperview()
}
pieceViews = []
setupGame()
layoutPieces()
}
fileprivate func layoutPieces() { //Copy of your layouting code in viewDidLayoutSubviews()
// Layout pieces
for pieceView in pieceViews {
let gridX = pieceView.location.x
let gridY = 7 - pieceView.location.y
let width = boardView.bounds.size.width / 8
let height = boardView.bounds.size.height / 8
pieceView.frame = CGRect(x: CGFloat(gridX) * width,
y: CGFloat(gridY) * height,
width: width,
height: height)
}
}
Past that I can't seem to find why I can no longer interact with the game. Any help would be greatly appreciated.
Once again, thanks for the great repo.
Alan
AI and AI player mode, app is crashing when I navigate back to MenuViewController. How to stop the AI action when the ViewController dismiss.
Hi
How can we code multi player for this game?
(Two Phones).
Hi
Can you please add a timer for the chess board?
Really appreciate your work.
thanks
See this commit here from this guy. He did it for a 3D game that uses SwiftChess as an engine: markypizz@36c9c85
Is this something that is necessary in the base implementation?
Hello @SteveBarnegren ! I would like to ask you about how strong your engine is? Have you ever made a bot on Lichess to estimate the rating?
A common ASCII representation king and knight are K and N, not G and K.
I want to add undo options, guide me on how to do undo?
Can you add Castling without pressing a button?
Hi,
How can we change Game levels?
Like easy, Medium, Hard.
Please tell us.
Thanks lot.
Moving g6 to e7 not working with Piece.PieceType.knight
Please help me
piece :Piece(type: SwiftChess.Piece.PieceType.knight, color: SwiftChess.Color.black, tag: Optional(0), hasMoved: false, canBeTakenByEnPassant: false, location: SwiftChess.BoardLocation(index: 0)), location: BoardLocation(index: 52)
Piece is unable to move to this location
How to use SwifChess with predefine PGN?
Is there a painless way to display a green circle on the board to show legal moves once a piece is touched?
I'd like to add undo function to my app.
What should I save and reload for this function?
Thank you.
Can you build a Korean chess engine?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.