Skip to content

Instantly share code, notes, and snippets.

@pauldwhitman
pauldwhitman / chessInCPart2-updatedBoardDrawingCode.c
Created March 11, 2013 02:38
Part of the "Chess in C" blog post series. Updated board drawing code to draw potential moves.
/* Print the board */
/* For every row */
for (i = 0;i <= 7; i++) {
/* And every column */
for (j = 0;j <= 7; j++){
/* Get the board value */
boardValue = board[i][j];
/* And print the contents */
switch (boardValue) {
@pauldwhitman
pauldwhitman / chessInCPart2-placeTwoPawns.c
Created March 11, 2013 02:39
Part of the "Chess in C" blog post series. Places two pawns on board.
/* Set initial start positions */
/*board[0][0] = ROOK;
board[0][1] = KNIGHT;
board[0][2] = BISHOP;
board[0][3] = QUEEN;
board[0][4] = KING;
board[0][5] = BISHOP;
board[0][6] = KNIGHT;
board[0][7] = ROOK;
board[1][0] = PAWN;*/
@pauldwhitman
pauldwhitman / chessInCPart2-pawnMoveOneSquareWithBug.c
Last active December 14, 2015 18:48
Part of the "Chess in C" blog post series. Calculates the square used by the pawn if it moves by one square. Intentionally contains an array out of bounds bug.
/* Calculate a pawn move */
/* For every row */
for (i = 0;i <= 7; i++) {
/* And every column */
for (j = 0;j <= 7; j++){
/* If this square contains a pawn.. */
if (board[i][j] == PAWN) {
/* ..mark the square below as being a potential move */
board[i+1][j] = POTENTIAL_MOVE_PAWN;
}
@pauldwhitman
pauldwhitman / chessInCPart2-pawnMoveOneOrThreeSquaresWithBug.c
Last active December 14, 2015 18:48
Part of the "Chess in C" blog post series. Calculates the square used by the pawn if it moves by one or three squares. Intentionally contains an array out of bounds bug.
/* Calculate a pawn move */
/* For every row */
for (i = 0;i <= 7; i++) {
/* And every column */
for (j = 0;j <= 7; j++){
/* If this square contains a pawn.. */
if (board[i][j] == PAWN) {
/* ..mark the square below as being a potential move */
board[i+1][j] = POTENTIAL_MOVE_PAWN;
@pauldwhitman
pauldwhitman / chessInCPart2-pawnMoveOneOrThreeSquaresCorrect.c
Created March 11, 2013 02:49
Part of the "Chess in C" blog post series. Calculates the square used by the pawn if it moves by one or three squares. Includes check to see whether pawn has reached the end of board/final row.
/* Calculate a pawn move */
/* For every row */
for (i = 0;i <= 7; i++) {
/* And every column */
for (j = 0;j <= 7; j++){
/* If this square contains a pawn.. */
if (board[i][j] == PAWN) {
/* ..and the pawn is NOT on the final row.. */
if (i != 7) {
/* ..mark the square below as being a potential move */
@pauldwhitman
pauldwhitman / chessInCPart6-upRightDiagonal.c
Last active December 14, 2015 22:39
Part of the "Chess in C" blog post series. Code to calculate the up-right diagonal.
/* Calculate possible up-right diagonal destinations.
* This requires the loop to iterate backwards as we are
* checking cells before the bishop. */
for (i=7; i>=0; i--) {
for (j=7; j>=0; j--){
/* If 1) the cell to left is inbounds of the array and
* 2) the cell isn't not on the final row */
if ((j-1 != -1) && (i != 7)) {
/* ...and the below-left cell has a bishop OR a breadcrumb... */
if (board[i+1][j-1] == BISHOP || board[i+1][j-1] == POTENTIAL_MOVE_BISHOP_UR) {
@pauldwhitman
pauldwhitman / chessInCPart6-start.c
Last active December 14, 2015 22:39
Part of the "Chess in C" blog post series. The code needed to start the lesson. Additional macros for potential bishop moves have been created so that the algorithms used to calculate each of the diagonals don't trip up over each other (from interpreting the other's breadcrumbs)
#include <stdio.h>
#include <stdlib.h>
#define EMPTY 0
#define KING 1
#define QUEEN 2
#define ROOK 3
#define KNIGHT 4
#define BISHOP 5
#define PAWN 6
#define BREADCRUMB 9
@pauldwhitman
pauldwhitman / chessInCPart6-complete.c
Created March 14, 2013 11:36
Part of the "Chess in C" blog post series. The complete code for part 6.
#include <stdio.h>
#include <stdlib.h>
#define EMPTY 0
#define KING 1
#define QUEEN 2
#define ROOK 3
#define KNIGHT 4
#define BISHOP 5
#define PAWN 6
#define BREADCRUMB 9
=ROUND(
IF(A1 > 960000 , 0.055 * A1,
IF(A1 > 130001 , 2870 + ( 0.06 * (A1 - 130000)),
IF(A1 > 25001 , 350 + ( 0.024 * (A1 - 25000)),
0.014 * A1)
))
,)
=ROUND(IF(A1>960000,A1*0.055,IF(A1>130001,(0.014*25000)+(0.024*(130000-25000))+(0.06*(A1-130000)),IF(A1>25001,(0.014*25000)+(0.024*(A1-25000)),A1*0.014))),)