Endgame Chess is our version of the capstone project for The Firehose Project, an intensive 15 week programming bootcamp. We are Team Endgame, 5 junior developers with different backgrounds working remotely to build the best chess app we can. With the support of our mentor, Travis Johnston, we followed Agile Methodology with weekly stand-ups to plan our sprints, kept our code in check using Git, and made sure everything worked with an extensive test suite. Some highlights include:

• Check and Mate Detection (view source)
• ``````
# Check Detection
def check(users_id, opponent_id)
opponent_pieces = pieces.where(user_id: opponent_id, captured: false)
king = pieces.find_by(user_id: users_id, type: "King")
opponent_pieces.each do |piece|
return true if piece.valid_move?(king.row_position, king.col_position)
end
false
end

# Checkmate Detection
def checkmate(id)
current_pieces = pieces.where(user_id: id, captured: false)
status = true
current_pieces.each do |piece|
8.times do |row|
8.times do |col|
status = false unless checkmate_check(piece, row, col)
end
end
end
status
end

# Transaction for Checkmate Detection
def checkmate_check(piece, row, col)
status = true
Piece.transaction do
piece.move_to!(row, col)
status = false unless determine_check
fail ActiveRecord::Rollback
end
status
end
``````
• State is important in chess. To determine the state of the game, we loop through each of your opponent’s pieces each turn and test them against your King. If one of those pieces has a valid move, the game is in Check. Check is never the result of user error (except for in strategy) -- you can’t purposely move into Check.
• You’ll want to get out of Check as soon as possible, since Checkmate means game over. In order to determine Checkmate, we loop through each of your pieces and see whether they can a) avoid b) block or c) capture the opponent piece that has your King in check. These checks are run in database transaction to ensure that none of the movements the game tries are saved (inadvertently helping you out).
• Drag and Drop Movement (view source)
• ``````
// Drag and drop using jQuery draggable and droppable
\$('.move_mode').draggable({ containment: '.board'});
\$( '.piece' ).droppable({
drop: function( event, ui ) {
\$(ui.draggable).detach().css({top: 0,left: 0});
\$(this).replaceWith(ui.draggable);
var draggableId = ui.draggable.attr("id");
var droppableId = \$(this).attr("pos");
var updateUrl = "/pieces/" + draggableId
var row = droppableId[0];
var col = droppableId[1];

// Update piece via AJAX
\$.ajax({
type: 'PUT',
url: updateUrl,
dataType: 'json',
data: { piece: {
row_position: row,
col_position: col
}},
complete: function(){
}
});
}
});

// Pusher for Real-Time Connection
var pusher = new Pusher(ENV['pusher_key'], {
encrypted: true
});

var gameId = \$('.pusherInfo').data('pusherinfo');

var channel = pusher.subscribe(gameId);

channel.bind('update-piece', function(data) {
});
``````
• Through the magic of jQuery, pieces are simply picked up and put down where you want them to go. An AJAX request handles updating the database and a Websockets connection with Pusher handles refreshing the page for both you and your opponent. Not too shabby.

# Open Source, Standards Driven, Full Service

Endgame Chess is a proud member open source community. You can view all of our code on GitHub. Additionally, Endgame Chess is built using open source tools.

## Ruby

All of our business logic is written in Ruby

## Rails

Rails is the foundation of Endgame Chess, bringing so many useful tools and conventions to make building it from scratch fast

Our team followed standard Agile and SCRUM methodologies, having a weekly virtual stand up to plan the week's sprints. We developed a solid test suite using Test Driven Design and used Rubocop to enforce best-practices in code style.

## Trello

We used Trello as an Agile board to keep track of the progress of all of our tickets

## Slack

Slack kept our team in constant communication

## Rubocop

Rubocop analyzed our code for style and best-practices

## Screenhero

Screenhero made it easy to pair program remotely

We were dedicated to finding the right tool for the job. Each of these services are best-in-class, allowing us to focus on developing Endgame Chess.

## Heroku

Heroku's Cloud Application Platform hosts the production version of Endgame Chess

## GitHub

GitHub was used extensively to display new work with pull requests, allow for comments during code review, and track issues as they came up

## Travis CI

Travis CI runs our Continuous Integration and our Continuous Deployment

## Pusher

Pusher uses Websockets to allow us to have real-time updates for pieces for both players