Answers.Body: <p>The number 1 goal is to make an engine that makes a <em>legal</em> move. The immediate next goal is to make an engine that calculates all legal moves - you can choose one at random.</p>
  <p>Next up is an evaluator - how good is a position? Again, we can start with a low goal - just consider checkmate to be the ultimate score, and count the pieces if the position is not checkmate. We can always improve the evaluation function, but you need one to get started.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-11-10T22:40:02.867Z
Answers.Text: This shouldn't be sold short. Simply evaluating legality and validity (both for generating moves and for validating player moves) is a much more challenging task than it might seem at first glance and writing a valid chess _board_ — not even engine — is a project I would expect to spend multiple days on.
Answers.UserDisplayName: Steven Stadnicki
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-11-09T09:10:22.947Z
Answers.LastActivityDate: 2021-11-09T09:10:22.947Z
Answers.UserDisplayName: MSalters
Answers.Body: <p>I think it has to be stated: you should start low.</p>
  <p>First of all, as we are interested in a chess <em>engine</em> you should not spend effort creating a user interface (not even a crude one). You sbould make your engine speak either <a href="https://www.chessprogramming.org/Chess_Engine_Communication_Protocol" rel="nofollow noreferrer">Chess Engine Communication Protocol</a> or <a href="https://www.chessprogramming.org/UCI" rel="nofollow noreferrer">UCI</a>. This way a number of existing graphical boards can be used with your engine, and lets you focus on the actual engine. This is exactly what is done by other engines such as Stockfish. And speaking the standard language for chess engines allows you run your program tests with other existing engines, to match against other programs, etc.</p>
  <p>Second, your program will have to use some kind of internal representation of the game state. This will be basically the state of the board <em>plus some additional flags</em> (is castling allowed? An <em>en-passant</em> is possible?) <a href="https://www.chessprogramming.org/Forsyth-Edwards_Notation" rel="nofollow noreferrer">Forsyth-Edwards Notation</a> shows what you have to take into account. You could operate directly on FEN strings, but internally you may use any representation you want. You will need to translate between FEN and your internal structures.</p>
  <p>Third, you will need to determine the moves you have available, as <a href="https://chess.stackexchange.com/a/37350/7985">noted by MSalters</a>. Initially make it pick a move at random.</p>
  <p>At this point, <em>you have a Minimum viable product</em>. You have made your own chess engine. It plays quite badly, but you made an engine. From this point on, you could run out of time with your college project and still provide a working project.</p>
  <p>Then the actual task is &quot;just&quot; making your engine <em>play well</em>, which is where things become really complex. You can build on existing algorithms, implement your own ideas and heuristics, etc.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-11-11T02:59:18.483Z
Answers.LastActivityDate: 2023-05-30T01:05:00.627Z
Answers.LastEditDate: 2023-05-30T01:05:00.627Z
Answers.UserDisplayName: Ángel
Answers.Body: <p>Others have mentioned <a href="http://www.chessprogramming.org" rel="nofollow noreferrer">www.chessprogramming.org</a>, but it does not seem to give a good explanation of <a href="https://chat.stackexchange.com/rooms/108579/conversation/negamax-alpha-beta-pruning">negamax with alpha-beta pruning</a>. You really need to understand this, as it is the key ingredient in getting an efficient chess engine. The static evaluation function is still important but much less than alpha-beta pruning and move-ordering heuristics and other pruning heuristics, as briefly mentioned in <a href="https://chess.stackexchange.com/a/29842/9192">this related post</a>. That is, if you replace the static evaluation function just by a checkmate checker plus a material balance evaluator, you would lose only a few moves of effective depth (i.e. you would need to search a few moves deeper to do as well as a better evaluation function that takes a small constant times as long to run). But if you remove alpha-beta pruning, your effective depth would be reduced by a significant fraction (possibly up to half)! And the move-ordering heuristics used with alpha-beta pruning as well as other pruning techniques would in general multiply the effective depth, hence improving them is very important!</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-11-09T20:03:27.720Z
Answers.Text: "you would lose only a few moves of effective depth": I disagree. If material balance is your only yardstick (except when mate is threatened), you will play a ridiculous game, choosing moves essentially at random (e.g. 1 Nc3 ... 2 Nb1). A reasonable static evaluation function is _extremely_ important if you want to play well. I agree that it might be a good idea to implement a basic search before adding the evaluation function, but the program will play hopelessly badly.
Answers.UserDisplayName: TonyK
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-11-09T20:37:54.343Z
Answers.Text: @TonyK: Not that badly. Yes the opening will be weird, but once the opponent starts on a good opening the correct responses would be strongly favoured *even with just material balance* as the position evaluation function. If you think otherwise, and have the time to experiment, try taking SF and making the change, and let us know how high depth is needed to make it the same strength as the full SF at depth 14?
Answers.UserDisplayName: user21820
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-11-09T20:48:27.970Z
Answers.Text: Well, we are both making unsubstantiated statements here. I am sure you are wrong, based on  my extensive experience as a chess programmer in the distant past. But I am certainly not going to re-program SF to prove it to you.
Answers.UserDisplayName: TonyK
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-11-09T20:51:44.743Z
Answers.Text: @TonyK: Haha no problem. I also have extensive experience at designing AI for abstract games and combinatorial optimization problems. In the future when I have time, I will try to come back here and do the necessary experiments. =)
Answers.UserDisplayName: user21820
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-11-09T09:20:53.047Z
Answers.LastActivityDate: 2021-11-09T09:20:53.047Z
Answers.UserDisplayName: user21820
Answers.Body: <p>I would recommend this <a href="https://www.youtube.com/watch?v=U4ogK0MIzqk&amp;t=847s&amp;ab_channel=SebastianLague" rel="nofollow noreferrer">video</a> by Sebastian Lague. It will not give you all the answers, probably, but it summarizes a process of how he himself tried making an engine from scratch and what he learned along the way.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-11-08T23:01:58.480Z
Answers.Text: Welcome to Chess! Whilst this may theoretically answer the question, [it would be preferable](//meta.stackexchange.com/q/8259) to include the essential parts of the answer here, and provide the link for reference.
Answers.UserDisplayName: Anton Menshov
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-11-11T14:25:00.047Z
Answers.Text: This. This is the correct answer. There's no way to summarise the video other than watch it yourself. it's exactly what OP's after a HowTo build an engine without much code to steal.
Answers.UserDisplayName: Иво Недев
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-11-08T22:34:56.163Z
Answers.LastActivityDate: 2021-11-08T22:34:56.163Z
Answers.UserDisplayName: Metju.Perry
Answers.Body: <p>If your main goal is the engine, you can get the basic functionality following this kind of guide (i.e. <a href="https://andreasstckl.medium.com/writing-a-chess-program-in-one-day-30daff4610ec" rel="noreferrer">https://andreasstckl.medium.com/writing-a-chess-program-in-one-day-30daff4610ec</a>). With this, you can develop the basics (that guide is in python, but you can follow along with other languages): board painting, piece managing... (things that may be out of scope for your interests: the engine).</p>
  <p>For creating a basic engine, you could start with this site: <a href="https://www.chessprogramming.org/Main_Page" rel="noreferrer">https://www.chessprogramming.org/Main_Page</a>, in which you will have content to create your engine (you'll get the concepts, not the code itself), like the simplified evaluation: <a href="https://www.chessprogramming.org/Simplified_Evaluation_Function" rel="noreferrer">https://www.chessprogramming.org/Simplified_Evaluation_Function</a></p>
  <p>With those concepts, you can enrich your engine as you go by.</p>
  <p>Hope this helps!</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-11-08T14:08:18.917Z
Answers.LastActivityDate: 2021-11-08T14:38:43.130Z
Answers.LastEditDate: 2021-11-08T14:38:43.130Z
Answers.UserDisplayName: Jesús María
Body: <p>I'm starting my college project to build my own chess engine. The problem is that I have no clue where to start or what to read. I found videos on YouTube but I don't want to be a copycat. I want to build it on my own. What should I read and how can I build it? Is there any chance that I can make it with my own ideas?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-11-09T15:33:58.313Z
Comments.Text: Don't worry about copycatting to ***a certain extent***.  Plagiarism will get you in trouble, but just copying certain techniques and general ways of setting things up is standard practice in software development.  If in doubt, ask the professor(s) where to draw the line.  I say this as a software developer.  Although, in this particular instance, I would advise you to go ahead and communicate with your professor(s) up front about using the same general techniques and setup, just to err on the side of caution.
Comments.UserDisplayName: Panzercrisis
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-11-09T18:28:49.157Z
Comments.Text: How ambitious a project is this intended to be?
Comments.UserDisplayName: RBarryYoung
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-11-09T21:42:05.947Z
Comments.Text: If you have to ask and it's just a project, don't. Most likely you'll spend a lot of time and have relatively little to show.
Comments.UserDisplayName: Bob Jansen
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-11-10T15:48:21.343Z
Comments.Text: As I mention I want to take the advantage of this project to learn and build stuff from my own ideas.
Comments.UserDisplayName: Ahmed M.Osman
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-11-11T13:33:32.733Z
Comments.Text: Computer Chess II by David Welsh was quite influential for me, though since it came out in the mid-80's I'd guess it was pretty dated today (everything is pre-OO programming).  On the other hand it was crucial for me in understanding alpha-beta pruning and it did have an description of the Negamax algorithm.
Comments.UserDisplayName: RBarryYoung
Tags: <engines><learning>
Title: Making my own chess engine for a college project
ThreadText: # Making my own chess engine for a college project
  
  (Asked by: username_0 on 2021-11-08)
  
  I'm starting my college project to build my own chess engine. The problem is that I have no clue where to start or what to read. I found videos on YouTube but I don't want to be a copycat. I want to build it on my own. What should I read and how can I build it? Is there any chance that I can make it with my own ideas?
  
  **Tags:** engines, learning
  
  > **Comments:**
  > **username_1**: Don't worry about copycatting to ***a certain extent***.  Plagiarism will get you in trouble, but just copying certain techniques and general ways of setting things up is standard practice in software development.  If in doubt, ask the professor(s) where to draw the line.  I say this as a software developer.  Although, in this particular instance, I would advise you to go ahead and communicate with your professor(s) up front about using the same general techniques and setup, just to err on the side of caution.  
  > **username_2**: How ambitious a project is this intended to be?  
  > **username_3**: If you have to ask and it's just a project, don't. Most likely you'll spend a lot of time and have relatively little to show.  
  > **username_0**: As I mention I want to take the advantage of this project to learn and build stuff from my own ideas.  
  > **username_2**: Computer Chess II by David Welsh was quite influential for me, though since it came out in the mid-80's I'd guess it was pretty dated today (everything is pre-OO programming).  On the other hand it was crucial for me in understanding alpha-beta pruning and it did have an description of the Negamax algorithm.  
  
  ---
  
  ## 5 answers
  
  ### Answer by username_12 on 2021-11-08. Score: 17 | Accepted answer
  
  If your main goal is the engine, you can get the basic functionality following this kind of guide (i.e. <https://andreasstckl.medium.com/writing-a-chess-program-in-one-day-30daff4610ec>). With this, you can develop the basics (that guide is in python, but you can follow along with other languages): board painting, piece managing... (things that may be out of scope for your interests: the engine).
  
  For creating a basic engine, you could start with this site: <https://www.chessprogramming.org/Main_Page>, in which you will have content to create your engine (you'll get the concepts, not the code itself), like the simplified evaluation: <https://www.chessprogramming.org/Simplified_Evaluation_Function>
  
  With those concepts, you can enrich your engine as you go by.
  
  Hope this helps!
  
  
  ---
  
  ### Answer by username_4 on 2021-11-09. Score: 30
  
  The number 1 goal is to make an engine that makes a *legal* move. The immediate next goal is to make an engine that calculates all legal moves - you can choose one at random.
  
  Next up is an evaluator - how good is a position? Again, we can start with a low goal - just consider checkmate to be the ultimate score, and count the pieces if the position is not checkmate. We can always improve the evaluation function, but you need one to get started.
  
  > **Comments:**
  > **username_5**: This shouldn't be sold short. Simply evaluating legality and validity (both for generating moves and for validating player moves) is a much more challenging task than it might seem at first glance and writing a valid chess _board_ — not even engine — is a project I would expect to spend multiple days on.  
  
  ---
  
  ### Answer by username_6 on 2021-11-11. Score: 6
  
  I think it has to be stated: you should start low.
  
  First of all, as we are interested in a chess *engine* you should not spend effort creating a user interface (not even a crude one). You sbould make your engine speak either [Chess Engine Communication Protocol](https://www.chessprogramming.org/Chess_Engine_Communication_Protocol) or [UCI](https://www.chessprogramming.org/UCI). This way a number of existing graphical boards can be used with your engine, and lets you focus on the actual engine. This is exactly what is done by other engines such as Stockfish. And speaking the standard language for chess engines allows you run your program tests with other existing engines, to match against other programs, etc.
  
  Second, your program will have to use some kind of internal representation of the game state. This will be basically the state of the board *plus some additional flags* (is castling allowed? An *en-passant* is possible?) [Forsyth-Edwards Notation](https://www.chessprogramming.org/Forsyth-Edwards_Notation) shows what you have to take into account. You could operate directly on FEN strings, but internally you may use any representation you want. You will need to translate between FEN and your internal structures.
  
  Third, you will need to determine the moves you have available, as [noted by username_4](https://chess.stackexchange.com/a/37350/7985). Initially make it pick a move at random.
  
  At this point, *you have a Minimum viable product*. You have made your own chess engine. It plays quite badly, but you made an engine. From this point on, you could run out of time with your college project and still provide a working project.
  
  Then the actual task is "just" making your engine *play well*, which is where things become really complex. You can build on existing algorithms, implement your own ideas and heuristics, etc.
  
  
  ---
  
  ### Answer by username_7 on 2021-11-09. Score: 4
  
  Others have mentioned [www.chessprogramming.org](http://www.chessprogramming.org), but it does not seem to give a good explanation of [negamax with alpha-beta pruning](https://chat.stackexchange.com/rooms/108579/conversation/negamax-alpha-beta-pruning). You really need to understand this, as it is the key ingredient in getting an efficient chess engine. The static evaluation function is still important but much less than alpha-beta pruning and move-ordering heuristics and other pruning heuristics, as briefly mentioned in [this related post](https://chess.stackexchange.com/a/29842/9192). That is, if you replace the static evaluation function just by a checkmate checker plus a material balance evaluator, you would lose only a few moves of effective depth (i.e. you would need to search a few moves deeper to do as well as a better evaluation function that takes a small constant times as long to run). But if you remove alpha-beta pruning, your effective depth would be reduced by a significant fraction (possibly up to half)! And the move-ordering heuristics used with alpha-beta pruning as well as other pruning techniques would in general multiply the effective depth, hence improving them is very important!
  
  > **Comments:**
  > **username_8**: "you would lose only a few moves of effective depth": I disagree. If material balance is your only yardstick (except when mate is threatened), you will play a ridiculous game, choosing moves essentially at random (e.g. 1 Nc3 ... 2 Nb1). A reasonable static evaluation function is _extremely_ important if you want to play well. I agree that it might be a good idea to implement a basic search before adding the evaluation function, but the program will play hopelessly badly.  
  > **username_7**: @username_8: Not that badly. Yes the opening will be weird, but once the opponent starts on a good opening the correct responses would be strongly favoured *even with just material balance* as the position evaluation function. If you think otherwise, and have the time to experiment, try taking SF and making the change, and let us know how high depth is needed to make it the same strength as the full SF at depth 14?  
  > **username_8**: Well, we are both making unsubstantiated statements here. I am sure you are wrong, based on  my extensive experience as a chess programmer in the distant past. But I am certainly not going to re-program SF to prove it to you.  
  > **username_7**: @username_8: Haha no problem. I also have extensive experience at designing AI for abstract games and combinatorial optimization problems. In the future when I have time, I will try to come back here and do the necessary experiments. =)  
  
  ---
  
  ### Answer by username_9 on 2021-11-08. Score: 3
  
  I would recommend this [video](https://www.youtube.com/watch?v=U4ogK0MIzqk&t=847s&ab_channel=SebastianLague) by Sebastian Lague. It will not give you all the answers, probably, but it summarizes a process of how he himself tried making an engine from scratch and what he learned along the way.
  
  > **Comments:**
  > **username_10**: Welcome to Chess! Whilst this may theoretically answer the question, [it would be preferable](//meta.stackexchange.com/q/8259) to include the essential parts of the answer here, and provide the link for reference.  
  > **username_11**: This. This is the correct answer. There's no way to summarise the video other than watch it yourself. it's exactly what OP's after a HowTo build an engine without much code to steal.  
  
  ---
  
  