user-1: I'm not enthusiastic about chess in particular, so if I use terminology incorrectly please correct me. I use "phase 1 & phase 2" for each player's move, and "turn n" for each pair of phases.
I'm a novice programmer writing a chess program as a personal challenge, and  would like to know exactly when checkmates and stalemates take effect. 
Specifically:

If a player 1's move causes checkmate or stalemate, does the game end during phase 1, or at the beginning of phase 2?

Edit:
It seems I wasn't clear enough that I wasn't looking for a programming answer, I wanted to know about chess standards. Even if my program can work without detecting the exact final phase, I would like that information to be available.
I looked at the FIDE rules as mentioned in Laska
's answer [link], and Section 5 points out what I was looking for:

5.1 a. The game is won by the player who has checkmated his opponent’s king. This immediately ends the game, provided that the move producing the checkmate
position was a legal move.
5.2 a. The game is drawn when the player to move has no legal move and his king is not in check. The game is said to end in ‘stalemate’. This immediately ends the game, provided that the move producing the stalemate position was legal.

From these rules I gather that if I cause a checkmate, the game ends before my opponent's next phase, and if I cause a stalemate, the game ends during my opponent's next phase.
Please correct me if you think I'm not understanding something correctly. Also, I know I've seen the term FIDE before but I'm not sure if their chess laws would generally be considered a widely accepted and robust standard. I figure a chess community is the right place to ask about whether or not I should be using their standards.

user4418: 
From these rules I gather that if I cause a checkmate, the game ends
  before my opponent's next phase, and if I cause a stalemate, the game
  ends during my opponent's next phase.

Your understanding is wrong. Both checkmate and stalemate take effect immediately the move has been made. The move is made immediately the player's hand loses contact with the piece. It happens even before the player presses the clock. Hence even if the player's flag falls the checkmate or stalemate still stands.
In your terminology both cause the game to end before the opponent's next phase.

Also, I know I've seen the term FIDE before but I'm not sure if their
  chess laws would generally be considered a widely accepted and robust
  standard

FIDE is the international chess federation. It stands for "Federation International des Echecs" and is French for "International Chess Federation". It is the chess equivalent of FIFA in the world of soccer. If you understand that the FIFA rules of soccer govern the play of soccer throughout the world then you will also understand that the FIDE Laws of Chess govern the play of chess throughout the world.
Individual chess federations (governing bodies of national chess federations) may vary some rules in special cases but when they do so the tournaments affected can not be internationally rated. They can only be nationally rated. 
The most common variation that I am aware of is that for competitions for weak/young players the rule which says that two illegal moves loses the game is suspended because these players play many illegal moves without thinking.

user924: Checkmate and stalemate end the game immediately, as soon as the move is played (that is, when the hand lets go of the piece -- but that's not relevant for computers).
If that move was White's, then that move was the last move of the game. Black never gets their turn, so in your terms "phase 2" of that turn doesn't exist.

user8201: Thanks for the question.
The FIDE rules are not great here. A turn ends when a game-ending move has been played (Article 6.2.a.1). The clock does not need to be pressed. But in order to compute whether the move ends the game, there has to have been some kind of hypothetical look-ahead as to what would happen at the beginning of the next turn. The simple purpose of this I suppose is to avoid the chance to lose on time after just having e.g. played a mating move.
A particular question is who has the move in the final position? In cases of mate it’s sort of obvious but in cases of stalemate it is not clear at all. Is this showing the position in the actual time or
the position in the hypothetical look-ahead? Argh!
However from a programming point of view this hypothecating is not necessary. The move is completed, and the opponent loses or is stalemated etc in their own turn. The final position cleanly shows who has the move.

user10075: Take your pick.
Conventionally in computer chess, we express your idea of phases as "plies", or half-moves, where 2 plies is one "turn".
You can detect checkmate in the ply where the checkmating move is made, but it is more common for checkmate to be detected in the following ply, where your program generates legal moves for the mated player, only to find that there are 0 available.
It is often more convenient and efficient that way, as the work to generate moves would have been done anyway had the position not been mate, so no extra work is done to determine whether a position is checkmate.

-1: <p>I'm not enthusiastic about chess in particular, so if I use terminology incorrectly please correct me. I use "phase 1 &amp; phase 2" for each player's move, and "turn <em>n</em>" for each pair of phases.</p>

<p>I'm a novice programmer writing a chess program as a personal challenge, and  would like to know exactly when checkmates and stalemates take effect. </p>

<p>Specifically:</p>

<ul>
<li>If a player 1's move causes checkmate or stalemate, does the game end during phase 1, or at the beginning of phase 2?</li>
</ul>

<h2>Edit:</h2>

<p>It seems I wasn't clear enough that I wasn't looking for a programming answer, I wanted to know about chess standards. Even if my program can work without detecting the exact final phase, I would like that information to be available.</p>

<p>I looked at the FIDE rules as mentioned in Laska
's answer [<a href="https://www.fide.com/FIDE/handbook/LawsOfChess.pdf" rel="nofollow noreferrer">link</a>], and Section 5 points out what I was looking for:</p>

<ul>
<li><p>5.1 a. The game is won by the <strong>player who has checkmated his opponent’s king</strong>. This <strong>immediately</strong> ends the game, provided that the move producing the checkmate
position was a legal move.</p></li>
<li><p>5.2 a. The game is drawn when the <strong>player to move</strong> has no legal move and his king is not in check. The game is said to end in ‘stalemate’. This <strong>immediately</strong> ends the game, provided that the move producing the stalemate position was legal.</p></li>
</ul>

<p>From these rules I gather that if I cause a checkmate, the game ends before my opponent's next phase, and if I cause a stalemate, the game ends during my opponent's next phase.</p>

<p>Please correct me if you think I'm not understanding something correctly. Also, I know I've seen the term FIDE before but I'm not sure if their chess laws would generally be considered a widely accepted and robust standard. I figure a chess community is the right place to ask about whether or not I should be using their standards.</p>
 4418: <blockquote>
  <p>From these rules I gather that if I cause a checkmate, the game ends
  before my opponent's next phase, and if I cause a stalemate, the game
  ends during my opponent's next phase.</p>
</blockquote>

<p>Your understanding is wrong. Both checkmate and stalemate take effect immediately the move has been made. The move is made immediately the player's hand loses contact with the piece. It happens even before the player presses the clock. Hence even if the player's flag falls the checkmate or stalemate still stands.</p>

<p>In your terminology both cause the game to end before the opponent's next phase.</p>

<blockquote>
  <p>Also, I know I've seen the term FIDE before but I'm not sure if their
  chess laws would generally be considered a widely accepted and robust
  standard</p>
</blockquote>

<p>FIDE is the international chess federation. It stands for "Federation International des Echecs" and is French for "International Chess Federation". It is the chess equivalent of FIFA in the world of soccer. If you understand that the FIFA rules of soccer govern the play of soccer throughout the world then you will also understand that the FIDE Laws of Chess govern the play of chess throughout the world.</p>

<p>Individual chess federations (governing bodies of national chess federations) may vary some rules in special cases but when they do so the tournaments affected can not be internationally rated. They can only be nationally rated. </p>

<p>The most common variation that I am aware of is that for competitions for weak/young players the rule which says that two illegal moves loses the game is suspended because these players play many illegal moves without thinking.</p>
 924: <p>Checkmate and stalemate end the game <em>immediately</em>, as soon as the move is played (that is, when the hand lets go of the piece -- but that's not relevant for computers).</p>
<p>If that move was White's, then that move was the last move of the game. Black never gets their turn, so in your terms &quot;phase 2&quot; of that turn doesn't exist.</p>
 8201: <p>Thanks for the question.</p>

<p>The FIDE rules are not great here. A turn ends when a game-ending move has been played (Article 6.2.a.1). The clock does not need to be pressed. But in order to compute whether the move ends the game, there has to have been some kind of hypothetical look-ahead as to what would happen at the beginning of the next turn. The simple purpose of this I suppose is to avoid the chance to lose on time after just having e.g. played a mating move.</p>

<p>A particular question is who has the move in the final position? In cases of mate it’s sort of obvious but in cases of stalemate it is not clear at all. Is this showing the position in the actual time or
the position in the hypothetical look-ahead? Argh!</p>

<p>However from a programming point of view this hypothecating is not necessary. The move is completed, and the opponent loses or is stalemated etc in their own turn. The final position cleanly shows who has the move.</p>
 10075: <p>Take your pick.</p>

<p>Conventionally in computer chess, we express your idea of phases as "plies", or half-moves, where 2 plies is one "turn".</p>

<p>You can detect checkmate in the ply where the checkmating move is made, but it is more common for checkmate to be detected in the following ply, where your program generates legal moves for the mated player, only to find that there are 0 available.</p>

<p>It is often more convenient and efficient that way, as the work to generate moves would have been done anyway had the position not been mate, so no extra work is done to determine whether a position is checkmate.</p>
