PC-Based Electronic Chess Board Game

146
STI College Makati PC-Based Electronic Chess Board Game A Thesis Project Presented to STI College Makati In Partial Fulfillment Of the Requirements for the Degree of Bachelor of Science in Computer Engineering By: Saliente, Peter John C. Ulama, Bernoullie M. Cuarteros, Ron Jyro L. Engr. Roel U. Viera Thesis Adviser March 2011

description

PC-based electronic chess board documentation

Transcript of PC-Based Electronic Chess Board Game

Page 1: PC-Based Electronic Chess Board Game

STI College – Makati

PC-Based Electronic Chess Board Game

A Thesis Project Presented to

STI College – Makati

In Partial Fulfillment

Of the Requirements for the Degree of

Bachelor of Science in Computer Engineering

By:

Saliente, Peter John C.

Ulama, Bernoullie M.

Cuarteros, Ron Jyro L.

Engr. Roel U. Viera

Thesis Adviser

March 2011

Page 2: PC-Based Electronic Chess Board Game

STI College–Makati

ADVISER’S RECOMMENDATION SHEET

This Thesis Project Entitled

PC-Based Electronic Chess Board Game

By:

Saliente, Peter John C.

Ulama, Bernoullie M.

Cuarteros, Ron Jyro L.

And submitted in partial fulfillment of the requirements of the

Bachelor of Science in Computer Engineering degree has been examined

and is recommended for acceptance and approval

Engr. Roel U. Viera

Thesis Adviser

March 2011

Page 3: PC-Based Electronic Chess Board Game

STI College – Makati

THESIS COORDINATOR AND DEAN’S

ACCEPTANCE SHEET

The Thesis ProjectEntitled

PC-Based Electronic Chess Board Game

After having been recommended and approved is hereby

accepted by the STI College – Makati

Engr. Laura M. Altea

Thesis Coordinator

Engr. Laura M. Altea

Dean

March 2011

Page 4: PC-Based Electronic Chess Board Game

STI College – Makati

PANEL’S APPROVAL SHEET

This Thesis Project Entitled

PC-Based Electronic Chess Board Game

Developed by:

Saliente, Peter John C.

Ulama, Bernoullie M.

Cuarteros, Ron Jyro L.

after having been presented is hereby approved

by the following members of panel

Mr. Riegie D. Tan Mr. Antonio M. Lazona

Panelist Panelist

Engr. Leodigario R. Bongco

Lead Panelist

Page 5: PC-Based Electronic Chess Board Game

TABLE OF CONTENTS

1. INTRODUCTION

1.1 Current State of Technology 1-1

1.2 Statement of the Problem 1-5

1.2.1 General Problem 1-5

1.2.2 Specific Problem 1-5

1.3 Objectives 1-6

1.3.1 General Objectives 1-6

1.3.2 Specific Objectives 1-7

1.4 Scope and Limitations 1-8

1.5 Review of Related Studies 1-9

1.5.1 Foreign Studies 1-9

1.5.1.1 Remote chess 1-9

1.5.1.2 MCU (chess robot) 1-10

1.5.1.3 The DGT Electronic Chessboard 1-10

2. THEORETICAL FRAMEWORK

2.1. Introduction 2-1

2.2. Electromagnetic Theory 2-1

2.3. Reed Switch 2-2

2.4. Logic Gate 2-4

2.5. Parallel Theory 2-4

Page 6: PC-Based Electronic Chess Board Game

3. PC-BASED ELECTRONIC CHESS BOARD GAME

3.1. Introduction 3-1

3.2. System Design Specification 3-1

3.2.1. Hardware 3-1

3.2.2. Software 3-3

4. PERFORMANCE ANALYSIS

4.1. Introduction 4-1

4.2. Experimental 4-1

4.2.1. Programming 4-1

4.2.1.1. Program Interface / Parallel Port 4-2

4.2.2. Hardware 4-2

4.2.2.1. Logic Gates 4-3

4.2.2.2. Touch Plates 4-3

4.2.2.3. Reed Switch 4-3

4.2.2.4. PIC Microcontroller 4-3

4.3. Results and Analysis 4-4

4.3.1. Programming 4-4

4.3.2. Hardware 4-4

4.4. Summary 4-5

5. CONCLUSION AND RECOMMENDATION

5.1 Conclusion 5-1

5.2 Recommendation 5-2

Page 7: PC-Based Electronic Chess Board Game

Bibliography

Appendices

Technical Vitae

Page 8: PC-Based Electronic Chess Board Game

LIST OF APPENDICES

Appendix A GANTT Chart

Appendix B Calendar of Activities

Appendix C List of Materials

Appendix D Program Listing

Appendix E User’s Manual

Appendix F Projects Photos/Screenshots

Page 9: PC-Based Electronic Chess Board Game

LIST OF FIGURES

Figure 1.1 Wooden Chess Board 1-1

Figure 1.2 Magnetic chess set 1-2

Figure 1.3 Analog Chess Clock 1-2

Figure 1.4 Chess Application 1-3

Figure 1.5 LED Chess Board 1-4

Figure 3.1 Hardware Block Diagram 3-1

Figure 3.2 Reed Switch 3-2

Figure 3.3 Software Block Diagram 3-3

Figure 3.4 Program User Interface 3-4

Page 10: PC-Based Electronic Chess Board Game

LIST OF TABLES

Table 4-1 Schedule of Experimental Activities 4-1

Table 4-2 Hardware Experimental Results 4-4

Page 11: PC-Based Electronic Chess Board Game

Acknowledgement

First of all, the developers would like to thank the people who unselfishly extend

their help. Mr. Joel Jimenez for giving the idea to develop the PC-Based Electronic Chess

Board Game. Mr. Ronald Hermida for the information of the official rules of the Chess

game which the developers applied on the project. The group’s beloved parents who give

their unconditional support and understanding. To Mr. Roel Viera, adviser of the group.

Dean Laura Altea, college dean of STI Makati. Mr.Riegie Tan, and Mr. Antonio Lazona.

Without their help it would be more difficult for the developers to create the project.

The group would like to thank, especially to their respective families for their

support. This project is dedicated to the parents of the developers for years of hardship

just for them to be educated.

And to God, thanks for his guidance. To him is all the glory.

Page 12: PC-Based Electronic Chess Board Game

ABSTRACT

Chess is one of the most popular board game all over the world. It can be played

by two persons or an Artificial Intelligent (A.I.) opponent on the net. The board has 64

squares where the chess piece is placed. The chess piece has two colors which is white

and black. Each player has 16 chess pieces. White player is always the first one to move.

The goal of the player is to checkmate his opponent’s king. The professional players of

chess are using clock because one way of determining who is the winner is the player that

does not consume most of his time.

The group develops the PC-Based Electronic Chess Board Game to enhance the

existing chess game and also to add other features that would make the game more

exciting and more fun. Using another alternative equipment to like acrylic glass and other

electronics component to make project possible for the developers. The group designs a

circuit that could interact to the PC for the simulation of the whole game. The series of

experiment that conducted by the group were very successful. As the game are being

played, the program is the one responsible for saving, loading, and recording the moves.

The board has sensors for communicating to the program through parallel port. The rules

of chess are still the same and it is applied to the program.

The PC-Based Electronic Chess Board Game is already functioning well and can

be played by both amateurs and professional players. The features that the developers

included are also properly working. Every player will enjoy the chess game because of

the said features and beginners will be familiar to the game as the project has a tutorial.

The group meets all the objectives of the project.

Page 13: PC-Based Electronic Chess Board Game

PC-Based Electronic Chess Board Game 1-1

1 INTRODUCTION

Chess is a strategy game played by two players on a checkered square board.

The board is made up of 64 alternating light and dark squares in eight rows and

columns. The board is always placed for play with a light square in the corner to the

right of each player. The pawns are placed on the second rank of each player. The

chess pieces are used to both attack and defend from attack, against the other player’s

chessmen. Each player’s goal is to attack the enemy king such that the king cannot

deflect or remove the attack and cannot escape.When either side’s king is trapped to

where it cannot move without being taken, it's called “checkmate" or the shortened

version "mate". Checkmate ends the game at once.

1.1 Current State of Technology

Figure 1.1Wooden Chess Set

Page 14: PC-Based Electronic Chess Board Game

PC-Based Electronic Chess Board Game 1-2

Figure 1.2Magnetic Chess set

On a regular game, players typically use a wooden chess board and pieces

although some (usually professional players) prefer using a mouse pad,especially

on a tournament. Magnetic chess set aren’t that much used by most of the players,

it is only commonly used by children who plays chess.Chess pieces for the

compact magnetic board are made of plastic and under each piece are magnets.

(See Figure 1.1 and Figure 1.2)

Like on the wooden chess set, the developers’ chess board is based on the

standard size of a regular chess board that commonly used by most of the players

(20” x 20”). From the magnetic chess set, the developers got the idea of having a

magnet placed under each chess piece that will act as a trigger to the sensors.

Figure 1.3Analog Chess Clock

Page 15: PC-Based Electronic Chess Board Game

PC-Based Electronic Chess Board Game 1-3

Analog chess clocks were one of the most common chess clocks being

used by professional players on a tournament and on a regular game, although

some players use digital chess clocks. (See Figure 1.3)Tournament games are

played under time constraints, called time controls, using a game clock. Each

player must make his moves within the time control or forfeit the game. There are

different types of time controls. In some cases each player will have a certain

amount of time to make a certain number of moves. In other cases each player

will have a limited amount of time to make all of his moves. Also, the player may

gain a small amount of additional time for each move made, either by a small

increment added for each move made, or by the clock delaying a small amount of

time each time it is started after the opponent's move

The developers use a timer that is represented digitally. The players will

no longer tap the clocks like on the typical chess game because the clocks are

already being automated by the developers.

Figure 1.4Chess Application

Page 16: PC-Based Electronic Chess Board Game

PC-Based Electronic Chess Board Game 1-4

Computer chess applications are becoming to be more popular, because

people who want to play against another human opponent, plays chess on the

computer and whenever an internet connection is available, some plays online.

(See Figure 1.4)

Most computer chess game shows all the possible moves of the piece to be

moved and some don’t. Though some computer chess applications are by default

shows the legal moves of a piece. The developers created a program that will be

simulating and recording the moves done by each player. The created program

also had the option of showing the possible moves of a lifted piece.

Figure 1.5LED Chess Board

The LED Chess Board is a stand alone project existing outside the country

that has been developed by students from a university, has the function of

showing legal moves(through LEDs)of the player who is on his turn. The LED

Chess Board can save the current game and load it anytime. Its timer is

represented by LEDs that decrease the number of glowing LEDs as time passes.

(See Figure 1.5)

Page 17: PC-Based Electronic Chess Board Game

PC-Based Electronic Chess Board Game 1-5

From the LED Chess Board, the project also has LEDs that will be

showing every possible moves of a lifted piece. The saving and loading of the

current game is only implemented at the software part of the project.

1.2 Statement of the Problem

People who are wanting to play chess that has less knowledge

about playing the game takes tutorial from other people who know more

about playing chess or buying and reading a book about the rules of

playing chess.

The project has some added features that can bring more

excitement and fun especially for the beginners. Tutorial on the actual

board are some of the features that are implemented in this project for

those who wants to learn more about Chess game.

1.2.1 General Problem:

How to design and develop a PC-Based Electronic Chess Board Game?

1.2.2 Specific Problems:

Hardware

How will the circuit interact to the PC?

How to detect the presence of a piece on the board?

How to scan 64 squares using 8 pins of the parallel port?

Page 18: PC-Based Electronic Chess Board Game

PC-Based Electronic Chess Board Game 1-6

Software

How will the visual basic program communicate using the parallel

port?

How will the developers determine if there has been a lifted piece on

the chess board?

How will the amateur players know the initial position of each piece?

How will the amateur players know the possible legal moves of a lifted

piece on its turn?

How to simulate the moves of the players to the PC to eliminate the

manual recording?

How to notify a player of an illegal move for Amateur Game Mode?

How to create a system that will record every legal move and make an

algorithm that will recognize what piece is on a specific square, special

moves like castling, en passant, or a pawn promotion and determine if

there is a check, checkmate, or stalemate?

1.3 Objectives

1.3.1 General Objective

To design and develop a PC-Based Electronic Chess Board Game.=

Page 19: PC-Based Electronic Chess Board Game

PC-Based Electronic Chess Board Game 1-7

1.3.2 Specific Objectives

Hardware

To make an electronic chess board that will interact to the PC via the

parallel port.

To sense the presence of a piece on the board by using pair of reed

switch as the trigger.

To scan 64 squares with only using 8 inputs of the parallel port by

scanning the board per column.

Software

To make a program communicate with the parallel port using a certain

DLL.

To determine if there has been a lifted piece on the chess board by

comparing the previous values and the current values that is sent

through the parallel port.

To create a program that will show the initial positions of each piece

To create an algorithm in the program that will display the possible

moves of a lifted piece on its turn.

To simulate the moves of the players to the PC to eliminate the manual

recording.

To notify a player of an illegal move for Amateur Game Mode.

To create a system that will record every legal move and make an

algorithm that will recognize what piece is on a specific square, special

moves like castling, en passant, or a pawn promotion and determine if

there is a check, checkmate, or stalemate?

Page 20: PC-Based Electronic Chess Board Game

PC-Based Electronic Chess Board Game 1-8

1.4 Scope and Limitations

Scope

Hardware

There is an indicator for the players turn

There is a switch button to pause and resume the timer of the players

after their turn

Software

The game is simulated to the PC

The program will show the possible moves of the player in Amateur

mode.

The program has an option to select between amateur and professional

game mode.

The project records the legal moves.

The program checks if the move is legal or not. If it is an illegal move,

the program will not record it.

The square of the losing player’s king will be blinking that indicates

that it has been checkmated.

The system can save and load the game.

Limitations

There are no Artificial Intelligence (AI) opponent or has the ability to

suggest the best move to win.

Each piece does not have the capability to move on its own.

Page 21: PC-Based Electronic Chess Board Game

PC-Based Electronic Chess Board Game 1-9

The project can not be used without a computer unit and a power

supply.

The players could not control the game or play on PC. The arbiter is

the only one who can control the program.

Each piece must be lifted at least 1 inch from the board and should not

be done in a sliding way, as the sensors used were really sensitive and

the program would treat the closest square as the final position of the

piece.

Amateur Game has no touch move rule.

1.5 Review of the Related Studies

1.5.1 Foreign Studies

Studies from other countries that were related either by their functions

and materials they usedthat were seen relevant and essential to the

development of the system.

1.5.1.1 Remote Chess

Remote Chess allows you play chess in real time against opponents

anywhere in the world so long as there is an internet connection. All that it

requires is a Remote Chess chessboard, a NTSC television, and a

computer running Matlab. [ANON2008]

In the project, the developers used the concept of using reed

switches from the Remote Chess as a sensor to detect the presence of each

Page 22: PC-Based Electronic Chess Board Game

PC-Based Electronic Chess Board Game 1-10

chess piece on the board, as this type of sensor is seen by the developers to

be easily implementedwith the design of the circuitry and on the chess

board.

1.5.1.2 MCU Chess (chess robot)

MCU chess or the chess robot that is also had been developed by

university students is a microcontroller based robot that plays chess

against a human player whereas MCU chess moves the chess pieces on its

own. [ANON2006]

In the project, the microcontroller is used to control 64 LEDs that

will be showing all the possible moves of a chess piece.The

microcontroller will be getting an input from the program and will be

using the data to display a certain pattern on the LED array depending on

the situation or on what piecebeing is lifted by the player.

1.5.1.3 The DGT Electronic Chessboard

DGT electronic chessboard is a product by Digital Game

Technology which is made from a genuine beautifully-inlaid wood board

and with the Classic Staunton wooden chess pieces with a king height of

95mm. DGT electronic chessboard can be connected to the computer to

play against with a chess program or an internet opponent. A DGT XL

clock can also be connected to the board. [ANON2009a]

Page 23: PC-Based Electronic Chess Board Game

PC-Based Electronic Chess Board Game 1-11

The project can also be connected to a computer to be able to

automatically record a game, the program also had an option to save and

load the current game. A digital timer can also be connected to the board

itself.

Page 24: PC-Based Electronic Chess Board Game

PC-Based Electronic Chess Board Game 2-1

2 THEORETICAL FRAMEWORK

2.1 Introduction

Theories are important in the completion of a project or any system. These

are the theories the proponents need to achieve the objectives set.

2.2 Electromagnetic Theory

Electricity is treated jointly with magnetism, because both generally

appear together; wherever electricity is in motion, magnetism is also present.

The phenomenon of magnetism was observed early in the history of magnetism,

but was not fully explained until the idea of magnetic induction was developed.

The phenomenon of electricity was observed early in the history of electricity,

but was not fully explained until the idea of electric charge was fully developed.

Originally electricity and magnetism were thought of as two separate forces.

Treatise on Electricity and Magnetismshows the interactions of positive and

negative charges were shown to be regulated by one force. There are four main

effects resulting from these interactions, all of which have been clearly

demonstrated by experiments:

1. Electric charges attract or repel one another with a force inversely

proportional to the square of the distance between them: unlike

charges attract, like ones repel.

Page 25: PC-Based Electronic Chess Board Game

PC-Based Electronic Chess Board Game 2-2

2. Magnetic poles (or states of polarization at individual points) attract or

repel one another in a similar way and always come in pairs: every

North Pole is yoked to a south pole.

3. An electric current in a wire creates a circular magnetic field around

the wire, its direction depending on that of the current.

4. A current is induced in a loop of wire when it is moved towards or

away from a magnetic field, or a magnet is moved towards or away

from it, the direction of current depending on that of the movement.

[ANON2010b]

When the electricity is in motion, the magnetism is present.

Magnetunder each piece has a magnet that serves as the trigger for the

reed switch. When the magnet is near to the reed switch, the metal

conductor attract to the other magnetic conductor and it will trigger to the

system. In terms of polarity of the magnet, reed switch will not triggerif

the orientation of the magnet is incorrect.

2.3 Reed Switch

A reed switch consists of a pair of ferrous metal contacts or three springy

metal reeds located inside a sealed glass tube. The reedswitch is enclosed in a

small tube, which is controlled by a magnet or magnetic field The two-reed

switch normally has open contacts that are closed while in operation, referred to

as (NO) contacts. The three-reed switch type, on the other hand, has a pair of

(NO) and a pair of normally closed contacts, which is referred to as (NC).

Page 26: PC-Based Electronic Chess Board Game

PC-Based Electronic Chess Board Game 2-3

The reed switch contains a pair (or more) of magnetically, flexible, metal

reeds whose end portions are separated by a small gap when the switch is open.

The reeds are hermetically sealed in opposite ends of a tubular glass envelope.

A magnetic field (from an electromagnet or a permanent magnet) will

cause the reeds to come together, thus completing an electrical circuit.

One important quality of the switch is its sensitivity, the amount of

magnetic field necessary to actuate it. Sensitivity is measured in units of

Ampere-turns, corresponding to the current in a coil multiplied by the number of

turns. Typical pull-in sensitivities for commercial devices are in the 10 to 60 AT

range. The lower the AT, the more sensitive the reed switches. Also, smaller

reed switches, which have smaller parts, are more sensitive to magnetic fields, so

the smaller the reed switch's glass envelope is, the more sensitive it is.

It works with the help of an additional magnet, which is placed within

close range of the switch. When the magnets make contact, they pull together

and complete an electrical circuit. This results in a change in the contacts to an

opposite state. As the magnetic field diminishes in the reedswitch, the switch and

its contacts immediately return to their original state. [ANON2010a]

The developers installed a pair of reed switch under the chess board that

acts as sensor. If a piece is on top of a square, then the reed switch will be

triggered on. Otherwise it is switched off as it is normally open.

Page 27: PC-Based Electronic Chess Board Game

PC-Based Electronic Chess Board Game 2-4

2.4 Logic Gate

A logicgate performs a logical operation on one or more logic inputs and

produces a single logic output. The logic normally performed is Boolean logic

and is most commonly found in digital circuits. Logic gates are primarily

implemented electronically using diodes or transistors, but can also be

constructed using electromagnetic relays, fluidics, optics, molecules, or even

mechanical elements.

Logic gates can have one or more inputs and produced an output

depending on its inputs. The developers take use of its function for taking 8

inputs from each square on row and use its output in the program.

2.5 Parallel Theory

ParallelPort, also called as PrinterPort is a 25 pin type of interface found

on computers to connect various peripherals. This is the most commonly used

interface for controlling electronic devices and projects. This port will allow the

input of up to 9 bits or the output of 12 bits at any one given time, thus requiring

minimal external circuitry to implement many simpler tasks. The port is

composed of 4 control lines, 5 status lines and 8 data lines [ANON2009b].

The parallel port is used by the developers as the physical connection

between the Electronic Chess Board and the Program. The developers choose the

parallel port because they are practically easy to control and use their outputs.

Page 28: PC-Based Electronic Chess Board Game

PC-Based Electronic Chess Board Game 3-1

3 PC-BASED ELECTRONIC CHESS BOARD GAME

3.1 Introduction

The group’s system design includes all the description and functionalities

of the prototype. In order to simulate the actual game, the group used a

programming language that will fit to the project. Visual Basic 6.0 is the one that

the group used. Then the signal coming from the Chess Board through the

parallel port will be send to the pc for the simulation of the program.

3.2 System Design Specification

3.2.1 Hardware

Figure 3.1 Hardware Block Diagram

First the CPU send signal to the Electronic Chess Board for the

Scanning Module to scan each column if there’s a piece on top of it. Then

sends signal back to the CPU. In Professional Game Mode, the players

turn ends until a player tap the button that will send signal to the

CPU.Then the CPU sends back a signal to the LEDs of the Electronic

Chess Board for the indicator of player’s turn for both game mode. The

Electronic Chess Board will send signal to the CPU for the program to run

the timer of the player’s on his turn and pause the opponent’s timer.

Page 29: PC-Based Electronic Chess Board Game

PC-Based Electronic Chess Board Game 3-2

Scanning Module – circuit that give signals to the PC simulator to detect

the certain piece moved by the players alternately.

Figure 3.2 Reed Switch

Reed Switch –switches on when it sense magnetic field produce under

each piece

CPU –record the moves of each player. Simulates and record the moves of

each player in the board.

Page 30: PC-Based Electronic Chess Board Game

PC-Based Electronic Chess Board Game 3-3

3.2.2 Software

Figure 3.3 Software Block Diagram

The block diagram shown above shows the communication and function

of the program. Visual Basic cannot directly communicate with the parallel port,

so the developers used a certain DLL to make the program interact with the

parallel port and communicate with the chessboard.From the initialization of the

program, the program sends a signal to the chessboard through the parallel port to

scan the chessboard per column and then sends back the status of the column to

the program. The program continually scans the chessboard and compares the

previous values to determine the location, type, and color of each piece.

Page 31: PC-Based Electronic Chess Board Game

PC-Based Electronic Chess Board Game 3-4

Figure 3.4Program User Interface

The program serves as the simulator of the actual chess game. If a player

lifted one of his pieces, the lifted piece will be simulated and it will just wait for

the player where would it be placed as the destination of that certain piece or the

new position of that piece.

1. The chess board where the simulation of the moves of the pieces is done.

2. Where the moves of each player is recorded automatically and ready to

be printed after the game.

3. It detects or scans whether a piece is on a certain block. It is represented

as 1 or 0 (for debugging purposes).

4. Represents the game mode that appropriate to the players.

5. Shows the previous and the current position.

6. Shows the whose player is on turn.

Page 32: PC-Based Electronic Chess Board Game

PC-Based Electronic Chess Board Game 3-5

7. Represents the time of each plyers.

8. For the game saved by the players which can be review.

Page 33: PC-Based Electronic Chess Board Game

PC-Based Electronic Chess Board Game 4-1

4 PERFORMANCE ANALYSIS

4.1 Introduction

The developers conducted a series of experiments to determine the actual

performance of the project.The proponents are to discuss the end result of

numerous experiments and theories that the group has done. The analysis will

determine that the proposed project had already achieved its objectives.

4.2 Experimental

The developers used a prototyping methodology, the theories and

Experiments are conducted to acquire the adjustments that the project needed to

achieve. Below are the series of experimental activities to aid the proponents.

Table 4-1 Schedule of Experimental Activities

May 2010 –

June 2010

July 2010 –

August 2010 September 2010

October 2010 –

November 2010

Logic Gates for

Scanner Module

Program Interface

ParallelPort

Touch Plates

Scanner Module

Reed Switch

Magnet

PIC Microcontroller

4.2.1 Programming

The toughest part in making this system to work is the creation of

an algorithm to scan and record the moves for both amateur and

Page 34: PC-Based Electronic Chess Board Game

PC-Based Electronic Chess Board Game 4-2

professional players, also in the PIC Microcontroller for the indicator of

the possible moves of each piece as a tutorial using Light Emitting Diode

(LEDs). Though the idea is simple that every move of the players is

recorded, the next thing is the consistency of our hardware and software to

send and receive signals. The indicator is another module to indicate the

possible moves for the beginner but the consistency of sending signal is

still the factor on the project.

4.2.1.1 Program Interface / ParallelPort

Visual Basic 6.0 was used to create the program interface

that will interact to the circuit via parallel port. Since VB6 can not

directly access the parallel port, certain DLL was used to be able to

access the port and had it tested on how it will work with VB6 so

that we can easily manipulate the data that the circuit will be

transmitting.

4.2.2 Hardware

The stage focuses more on implementing the actual structure of the

project; this includes the actual size of the chess board, the chess pieces

will be used, and proper wiring. This is to test how the overall hardware

implementation of the project works. The proponents subjected the

prototype to a test run by trying to play an actual game in succession. All

problems during the batch run will be analyzed so they can be properly

addressed.

Page 35: PC-Based Electronic Chess Board Game

PC-Based Electronic Chess Board Game 4-3

4.2.2.1 Logic Gates

To be able to connect 64 sensors to a much fewer 8 data

port of the parallel port, logic gates were tested on how it will

efficiently work to reduce its number.

4.2.2.2 Touch Plates

Touch plates are inexpensive and easy to use as a sensor for

every block. It will work like a switch and will trigger when the

conductive material under each piece touches the pair of plates.

4.2.2.3 Reed Switch

Reed switch were efficient enough to be used as a sensor

for every block, it produce less noise than that of a touch plate as it

only use nearby magnetic field as its trigger. Reed switch were

tested with the circuit while usingmagnets under each chess piece

as its trigger.

4.2.2.4 PIC Microcontroller

Parallel port’s outputs were no longer enough to be used for

the manipulation of 64 LEDs on the chess board, as an alternative,

the Serial Port was connected to a microcontroller that will

interpret the data and control the 64 LEDs. An experiment has

been conducted to the PIC16F877A on how it will work and what

will be the easiest way to program the PIC.

Page 36: PC-Based Electronic Chess Board Game

PC-Based Electronic Chess Board Game 4-4

4.3 Results and Analysis

4.3.1 Programming

After examining and debugging the code that would control our

hardware and software, it is now possible to play the chess using our

project and the other features in it especially for the amateur players.The

program has successfully been able to communicate with the parallel port

as the result of the conducted experiment.

4.3.2 Hardware

To achieve the objectives of the project, a series of experiments

was conducted. The following table below shows the results of each

experiment.

Table 4-2 Hardware Experimental Results

Experiment Results Actions Taken /

Improvement

Logic Gates Logic gates were able to demultiplex

64 data inputs into 8 data output

Logic Gateswere used and

included in the scanner

module

Touch Plates

The touch plates causes fluctuation

because of the uneven surface and

poor contact between the conductive

material under each piece

Touch plates were replaced

Reed Switch

It produces less noise than the touch

plates and is more effective in

transmitting digital signalbut wasn’t

able to sense some of the magnets

Magnets were replaced with

more stronger magnetic field

and was oriented properly

Page 37: PC-Based Electronic Chess Board Game

PC-Based Electronic Chess Board Game 4-5

4.4 Summary

Based on the developers’ objective on the project, the results of the

experiments were satisfying and had greatly helped and improved the systems

development. The hardware is functioning as well as the program. The

transmission of signals between the hardware and the program is responding very

well. The actual chess board must be more presentable enough for the next

presentation.

Page 38: PC-Based Electronic Chess Board Game

PC-Based Electronic Chess Board Game 5-1

5 CONCLUSION AND RECOMMENDATION

5.1 Conclusion

The developers were able to meet the expected objectives and function of

the projects based on the research that are conducted. The interaction between

the module and the program are functioning as well as the scanning of the 64

squares of the chess board. The reed switches which serves as the triggering

device can already detect the presence of the chess pieces. On the software part,

the program are working properly by using certain DLL for the Visual Basic 6.0

to communicate to the parallel port. For determining a lifted piece, the program

has a piece tracker that indicates logic 1 and 0 means there is a certain piece or it

has no piece on a specific square respectively. The amateur players will be

familiar because the program shows the standard position of the chess piece

before the game starts and also the possible moves of each piece. The program

also shows an error message to notify them that they committed an illegal move.

The actual game of the chess is simulated on the program and also the rules of

the chess are applied to the program.

After all the conducted experimentations and the researches, the results

were very satisfying to the developers. The projects can now be played by both

amateur and professional players. Therefore, developing the PC-Based

Electronic Chess Board Game, giving the players a unique experience and

enjoyment of playing chess.

Page 39: PC-Based Electronic Chess Board Game

PC-Based Electronic Chess Board Game 5-2

5.2 Recommendation

For future enhancements, the developers recommends to make use of a

more accurate and faster sensor or a better type of reed switch, the digital clock

which is more preferable to the professional players to see their time, and the

showing of the possible legal moves on the actual chess board created by the

developers.

Page 40: PC-Based Electronic Chess Board Game

Bibliography

World Wide Web

[ANON2006] MCUCHESS[2006]

http://courses.cit.cornell.edu/ee476/FinalProjects/s2006/um

h3_fcf3/index.html

[ANON2008] REMOTECHESS[2008]

http://courses.cit.cornell.edu/ee476/FinalProjects/s2008/eaj

24_wpb3/eaj24_wpb3/index.html

[ANON2009a] DGTCHESS[2009]

http://digitalgametechnology.com/site/index.php/Electronic

-Boards/

[ANON2009b] PARALLELPORT[2009]

“Interfacing the standard parallel port

http://beyondlogic.org/spp/parallel.htm#1

[ANON2010a] REEDSWITCH[2010]

http://www.wisegeek.com/what-is-a-reed-switch.html

[ANON2010b] ELCTROMAGNETICTHEORY[2010]

http://en.wikipedia.org/wiki/Electomagnetism

Page 41: PC-Based Electronic Chess Board Game

APPENDIX

Page 42: PC-Based Electronic Chess Board Game

APPENDIX A

GANTT Chart

Page 43: PC-Based Electronic Chess Board Game

Appendix A A-1

Appendix A - GANTT Chart of Activities

Projected – BLUE .

Actual – RED .

Page 44: PC-Based Electronic Chess Board Game

Appendix A A-2

Page 45: PC-Based Electronic Chess Board Game

APPENDIX B

Calendar of Activities

Page 46: PC-Based Electronic Chess Board Game

Appendix B B-1

Appendix B - Calendar of Activities

Requirements Analysis

November 2009 – March 2010 - Data Gathering

Searched inside and outside the school using internet on what

possible projects will the group proposing.

November 2009 – March 2010 – System Analysis

Analyze all applications about the system including parts,

functions, etc.

March 2010 – June 2010 – Prototype Designing

Choosing thebetter design for the upcoming prototype.

Prototype Construction

April 2010 – August 2010 – Software Coding

VB6 – The proponents will encode a program that will simulate

the movement of the pieces on the board as well as communicating

with the board.

April 2010 – September 2010 – HardwareBuilding

Prototype construction – includes all aspects of prototype building

like cutting, drilling, etc.

Circuits making - designing and developing circuits needed like

the Logic gates.

Page 47: PC-Based Electronic Chess Board Game

APPENDIX C

List of Materials

Page 48: PC-Based Electronic Chess Board Game

Appendix C – Cost of Materials

Materials Cost

Fiber Glass P 1080

Glass Chess Set P 700

Magnets P 437

Plywood / Wood /

Nails

P 1,650

Circuit Components

(IC, Resistors, etc.)

P 11,851.50

Other Expenses P 4347

Total Materials Expenses: P 20,065.50

Page 49: PC-Based Electronic Chess Board Game

APPENDIX D

Program Listing

Page 50: PC-Based Electronic Chess Board Game

Appendix D D-1

Appendix D – Program Listing

Form1

Dim blackturn As Boolean, whiteturn As Boolean

Dim picked As Boolean, bpicked As Boolean

Dim pawnpromoted As Boolean, opponentpiecelifted As Boolean, posopl As Integer, opl As Integer,

beyondenemylines As Boolean

Dim position As Integer, piecenum As Integer, piece As String, movefrom As String, moveto As String, tagcounter

As Integer, counter As Integer

Dim piecechose As Integer, stops As Boolean, castling As Boolean, rook As Integer, rookdes As Integer

Dim blocked As Boolean

Dim checked As Boolean Dim kingpos As Integer

Dim enpassantpiecew(1 To 8) As Boolean,

enpassantpieceb(1 To 8) As Boolean Dim whitepawnmoved(1 To 8) As Boolean,

blackpawnmoved(1 To 8) As Boolean

Dim kingblackmoved As Boolean, kingwhitemoved As Boolean

Dim rightrookwhitemoved As Boolean, leftrookwhitemoved As Boolean, rightrookblackmoved As Boolean,

leftrookblackmoved As Boolean

Dim block(1 To 64) As Integer, tmp(1 To 64) As Integer Dim datainput As Integer

Dim column As Integer, trigger As Boolean

Dim anong_bit As Integer, maliwanag_ang_buhay As Integer, meralco(1 To 64) As Integer, num As Integer, num2

As Integer

Dim pieceischeck(16) As Boolean

Dim loadfilelocation As String

Dim error As Integer, timer4cnt As Integer Dim piecepromoted As String, bturn2 As Integer

Dim blk(1 To 64) As Integer, sum1 As Integer, sum2 As

Integer, trgr As Boolean, listcnt As Integer Dim boolforpatong As Boolean, posdes As Integer

' -- manny's variables --

Dim changed_tiles(1 To 35) As Integer, changed_tiles_count As Integer, draw As Boolean

Dim castling_king_side As Boolean, castling_queen_side As

Boolean, mcastling As Boolean

Dim castling_king_sideb As Boolean, castling_queen_sideb

As Boolean, mcastlingb As Boolean

Dim led_array(1 To 64) As Integer, led_column(1 To 8) As Integer, sqctr As Integer, checkmate As Boolean

Dim mpassed_pawn As Integer, black_piece As Integer,

white_piece As Integer, squares_to_be_blocked(1 To 64) As Integer

Dim blink_trigger As Boolean, manny_piece As String,

move_count As Integer, lala As Integer Dim black_pos(1 To 16, 500) As String, white_pos(1 To 16,

500) As String, OpenCheckTiles(1 To 64) As Integer

Dim OpenCheckTilesCount As Integer, takboctr As Integer, kukai As String, run_cnt As Integer, hula As Boolean

Dim ppp As Integer, ProSw As Integer, ProTaba As Integer

Private Function alamin_ang_pwesto(c As Integer, r As

Integer) As Integer

alamin_ang_pwesto = r + (8 * (c - 1)) End Function

Private Function autoseyb()

listcnt = lst_moves.ListCount

Open App.Path & "\save\" & currentsavefile & ".txt" For Output As #1

For i = 1 To 16 Print #1, Image6(i).Left

Next i

For i = 1 To 16 Print #1, Image6(i).Top

Next i

For i = 1 To 16 Print #1, Image6(i).Tag

Next i

For i = 1 To 16 Print #1, Image7(i).Left

Next i

For i = 1 To 16 Print #1, Image7(i).Top

Next i

For i = 1 To 16 Print #1, Image7(i).Tag

Next i

Print #1, turn

Print #1, gamemode

Print #1, timerw(0) Print #1, timerw(1)

Print #1, timerb(0)

Print #1, timerb(1)

Print #1, listcnt - 1

For i = 0 To listcnt - 1

Print #1, lst_moves.List(i)

Next i

Print #1, kingblackmoved

Print #1, kingwhitemoved Print #1, rightrookwhitemoved

Print #1, leftrookwhitemoved

Print #1, rightrookblackmoved

Print #1, leftrookblackmoved

Print #1, mcastling Print #1, castling_queen_side

Print #1, castling_king_side

Print #1, mcastlingb Print #1, castling_queen_sideb

Print #1, castling_king_sideb

Print #1, checkmate Print #1, draw

Print #1, move_count - 1

Print #1, hula

For t = 1 To 8

Print #1, whitepawnmoved(t) Print #1, blackpawnmoved(t)

Print #1, enpassantpiecew(t)

Print #1, enpassantpieceb(t) Next t

For i = 0 To move_count - 1

Page 51: PC-Based Electronic Chess Board Game

Appendix D D-2

For j = 1 To 16

Print #1, white_pos(j, i) Print #1, black_pos(j, i)

Next j

Next i Print #1, "pogi ako"

Close #1

End Function

Private Function check() As Boolean

Dim pos_c As Integer, pos_r As Integer, squares As Integer Dim kl As Integer, kr As Integer, j As Integer, k As Integer

Dim mlimit As Integer, hakbang As Integer

check = False sqctr = 0

If whiteturn Then For i = 1 To 64

If Image6(13).Top = Image1(i).Top And Image6(13).Left =

Image1(i).Left Then kingpos = i

pos_c = what_column(kingpos)

pos_r = what_row(kingpos) i = 64

End If

Next i

For j = 1 To -1 Step -2 ' 1 right, -1 left If pos_c + j <= 8 And pos_c + j >= 1 And pos_r > 1 Then

squares = alamin_ang_pwesto(pos_c + j, pos_r - 1)

If is_black_piece(squares, 1) Then check = True

inc_blocks (squares)

j = -1 End If

End If

Next j

For i = 0 To 7

Select Case i Case 0, 5

kl = -1

Case 1, 4 kl = 1

Case 2, 3

kl = 2 Case 6, 7

kl = -2

End Select

Select Case i

Case 0, 1

kr = -2 Case 2, 7

kr = -1

Case 3, 6 kr = 1

Case 4, 5

kr = 2 End Select

If (pos_c + kl) <= 8 And (pos_c + kl) >= 1 And (pos_r + kr)

<= 8 And (pos_r + kr) >= 1 Then squares = alamin_ang_pwesto(pos_c + kl, pos_r + kr)

If is_black_piece(squares, 0) Then

If black_piece > 0 Then If Image7(black_piece).Tag = "N" Then

check = True

inc_blocks (squares) GoTo end_check

End If

End If

End If

End If Next i

For i = 0 To 1 '0=horizontal, 1=vertical hakbang = 1

For j = 1 To 8 Step 7 '1=decreasing, 8=increasing

hakbang = hakbang * -1 kl = pos_c

kr = pos_r

If i = 0 Then mlimit = kl

Else

mlimit = kr End If

'lbldebug.Caption = "W" & vbCrLf

If mlimit <> j Then For k = mlimit + hakbang To j Step hakbang

If i = 0 Then

squares = alamin_ang_pwesto(k, kr) Else

squares = alamin_ang_pwesto(kl, k)

End If inc_blocks (squares)

'lbldebug.Caption = lbldebug.Caption &

squares_to_be_blocked(sqctr) & "," & block(squares) & vbCrLf

If block(squares) = 1 Then If is_black_piece(squares, 0) Then

'If black_piece > 0 Then

If (Image7(black_piece).Tag = "Q" Or Image7(black_piece).Tag = "R") Then

check = True

GoTo end_check End If

'End If

End If k = j

End If

If k = j Then sqctr = 0

End If

Next k End If

Next j

Next i

'************

'* diagonal *

'************

For i = 7 To 9 Step 2 ' 7=downward , 9=upward

For j = kingpos - i To 1 Step -i 'towards left If Image1(kingpos).Tag = Image1(j).Tag Then

inc_blocks (j)

If block(j) = 1 Then If is_black_piece(j, 0) Then

'If black_piece > 0 Then

If (Image7(black_piece).Tag = "B" Or Image7(black_piece).Tag = "Q") Then

check = True

GoTo end_check End If

'End If

End If j = 1

End If

If j <= 1 Then sqctr = 0

End If

End If

Page 52: PC-Based Electronic Chess Board Game

Appendix D D-3

Next j

For j = kingpos + i To 64 Step i 'towards right If Image1(kingpos).Tag = Image1(j).Tag Then

inc_blocks (j)

If block(j) = 1 Then If is_black_piece(j, 0) Then

'If black_piece > 0 Then

If (Image7(black_piece).Tag = "B" Or Image7(black_piece).Tag = "Q") Then

check = True

GoTo end_check End If

'End If

End If j = 64

End If

If j >= 64 Then sqctr = 0

End If

End If Next j

Next i

End If 'whiteturn

If blackturn Then

For i = 1 To 64 If Image7(13).Top = Image1(i).Top And Image7(13).Left =

Image1(i).Left Then kingpos = i

pos_c = what_column(kingpos)

pos_r = what_row(kingpos) i = 64

End If

Next i

For j = 1 To -1 Step -2 ' 1 right, -1 left

If pos_c + j <= 8 And pos_c + j >= 1 And pos_r < 8 Then squares = alamin_ang_pwesto(pos_c + j, pos_r + 1)

If is_white_piece(squares, 1) Then

check = True inc_blocks (squares)

GoTo end_check

j = -1 End If

End If

Next j '**********

'* kabayo *

'**********

For i = 0 To 7

Select Case i

Case 0, 5 kl = -1

Case 1, 4

kl = 1 Case 2, 3

kl = 2

Case 6, 7 kl = -2

End Select

Select Case i Case 0, 1

kr = -2

Case 2, 7 kr = -1

Case 3, 6

kr = 1 Case 4, 5

kr = 2

End Select

If (pos_c + kl) <= 8 And (pos_c + kl) >= 1 And (pos_r + kr)

<= 8 And (pos_r + kr) >= 1 Then squares = alamin_ang_pwesto(pos_c + kl, pos_r + kr)

If is_white_piece(squares, 0) Then

If white_piece > 0 Then If Image6(white_piece).Tag = "N" Then

check = True

inc_blocks (squares) GoTo end_check

End If

End If End If

End If

Next i

For i = 0 To 1 '0=horizontal, 1=vertical

hakbang = 1 For j = 1 To 8 Step 7 '1=decreasing, 8=increasing

hakbang = hakbang * -1

kl = pos_c kr = pos_r

'sqctr = 0

If i = 0 Then mlimit = kl

Else

mlimit = kr End If

'lbldebug.Caption = "B" & vbCrLf If mlimit <> j Then

For k = mlimit + hakbang To j Step hakbang

If i = 0 Then squares = alamin_ang_pwesto(k, kr)

Else

squares = alamin_ang_pwesto(kl, k) End If

inc_blocks (squares)

'lbldebug.Caption = lbldebug.Caption & squares_to_be_blocked(sqctr) & "," & block(squares) &

vbCrLf

If block(squares) = 1 Then If is_white_piece(squares, 0) Then

'If white_piece > 0 Then

If (Image6(white_piece).Tag = "Q" Or Image6(white_piece).Tag = "R") Then

check = True

GoTo end_check End If

'End If

End If

k = j

End If

If k = j Then sqctr = 0

End If

Next k End If

Next j

Next i

'************

'* diagonal * '************

For i = 7 To 9 Step 2 ' 7=downward , 9=upward

For j = kingpos - i To 1 Step -i 'towards left If Image1(kingpos).Tag = Image1(j).Tag Then

inc_blocks (j)

If block(j) = 1 Then If is_white_piece(j, 0) Then

If (Image6(white_piece).Tag = "B" Or

Image6(white_piece).Tag = "Q") Then

Page 53: PC-Based Electronic Chess Board Game

Appendix D D-4

check = True

GoTo end_check End If

End If

j = 1 End If

If j <= 1 Then

sqctr = 0 End If

End If

Next j For j = kingpos + i To 64 Step i 'towards right

If Image1(kingpos).Tag = Image1(j).Tag Then

inc_blocks (j) If block(j) = 1 Then

If is_white_piece(j, 0) Then

If (Image6(white_piece).Tag = "B" Or Image6(white_piece).Tag = "Q") Then

check = True

GoTo end_check End If

End If

j = 64 End If

If j >= 64 Then

sqctr = 0 End If

End If Next j

Next i

End If 'blackturn end_check:

checked = check

'Label4.Caption = check If check Then

kukai = "CHECK!"

Timer6.Enabled = True may_threat (kingpos)

End If

End Function Private Function checkmate_ba() As Boolean

Dim kolum As Integer, kurow As Integer, loops As Integer,

pwesto_ng_kalaban As Integer, mlimit As Integer Dim i As Integer, j As Integer, hakbang As Integer, piecete

As String, local_pos As Integer

Dim kl As Integer, kr As Integer checkmate_ba = True

For local_pos = 1 To 64

kolum = what_column(local_pos)

kurow = what_row(local_pos)

If whiteturn Then

If is_white_piece(local_pos, 0) Then piecete = Image6(white_piece).Tag

Select Case piecete

Case "P" '*********************

'* walang nakaharang *

'********************* If Not blocked Then

If kurow = 7 Then

loops = 2 Else

loops = 1

End If For i = 1 To loops

If block(local_pos - i) = 0 Then

If checked And naharangan_ba(local_pos - i) Then checkmate_ba = False

GoTo end_checkmate_ba

End If

End If

Next End If 'not blocked

'****************

'* may makakain * '****************

For j = 1 To -1 Step -2

If kolum + j <= 8 And kolum + j >= 1 And kurow > 1 Then pwesto_ng_kalaban = alamin_ang_pwesto(kolum + j, kurow

- 1)

If is_black_piece(pwesto_ng_kalaban, 0) Then If checked And naharangan_ba(pwesto_ng_kalaban) Then

checkmate_ba = False

GoTo end_checkmate_ba End If

End If

End If Next j

'***************

'* passed pawn * '***************

For j = 1 To -1 Step -2

If kolum + j <= 8 And kolum + j >= 1 And kurow > 1 Then pwesto_ng_kalaban = alamin_ang_pwesto(kolum + j, kurow)

If is_black_piece(pwesto_ng_kalaban, 1) And

mpassed_pawn <> 0 Then If enpassantpieceb(mpassed_pawn) Then

If checked And naharangan_ba(pwesto_ng_kalaban) Then checkmate_ba = False

GoTo end_checkmate_ba

End If End If

End If

End If Next j

'**********

'* kabayo * '**********

Case "N"

If Not blocked Then For i = 0 To 7

Select Case i

Case 0, 5 kl = -1

Case 1, 4

kl = 1 Case 2, 3

kl = 2

Case 6, 7

kl = -2

End Select

Select Case i Case 0, 1

kr = -2

Case 2, 7 kr = -1

Case 3, 6

kr = 1 Case 4, 5

kr = 2

End Select If (kolum + kl) <= 8 And (kolum + kl) >= 1 And (kurow +

kr) <= 8 And (kurow + kr) >= 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum + kl, kurow + kr)

If is_black_piece(pwesto_ng_kalaban, 0) Or

block(pwesto_ng_kalaban) = 0 Then If checked And naharangan_ba(pwesto_ng_kalaban) Then

checkmate_ba = False

GoTo end_checkmate_ba

Page 54: PC-Based Electronic Chess Board Game

Appendix D D-5

End If

End If End If

Next i

End If 'not blocked '********

'* tore *

'******** Case "R"

If Not blocked Then

For i = 0 To 1 '0=horizontal, 1=vertical hakbang = 1

For j = 1 To 8 Step 7 '1=decreasing, 8=increasing

hakbang = hakbang * -1 kl = kolum

kr = kurow

If i = 0 Then mlimit = kl

Else

mlimit = kr End If

pwesto_ng_kalaban = alamin_ang_pwesto(kl, kr)

Do Until mlimit = j + hakbang Or block(pwesto_ng_kalaban) = 1

pwesto_ng_kalaban = alamin_ang_pwesto(kl, kr)

If i = 0 Then kl = kl + hakbang

mlimit = kl Else

kr = kr + hakbang

mlimit = kr End If

If local_pos <> pwesto_ng_kalaban Then

If (is_black_piece(pwesto_ng_kalaban, 0) Or block(pwesto_ng_kalaban) = 0) Then

If checked And naharangan_ba(pwesto_ng_kalaban) Then

checkmate_ba = False GoTo end_checkmate_ba

End If

End If End If

Loop

Next j Next i

End If

'********** '* bishop *

'**********

Case "B"

If Not blocked Then

'************

'* diagonal * '************

For i = 7 To 9 Step 2 ' 7=downward , 9=upward

For j = local_pos - i To 1 Step -i 'towards left If (block(j) = 0 Or is_black_piece(j, 0)) And

Image1(local_pos).Tag = Image1(j).Tag Then

If checked And naharangan_ba(j) Then checkmate_ba = False

GoTo end_checkmate_ba

End If End If

If block(j) = 1 Then

j = 1 End If

Next j

For j = local_pos + i To 64 Step i 'towards right If (block(j) = 0 Or is_black_piece(j, 0)) And

Image1(local_pos).Tag = Image1(j).Tag Then

If checked And naharangan_ba(j) Then

checkmate_ba = False

GoTo end_checkmate_ba End If

End If

If block(j) = 1 Then j = 64

End If

Next j Next i

End If 'blocked

'********* '* reyna *

'*********

Case "Q" If Not blocked Then

For i = 0 To 1 '0=horizontal, 1=vertical

hakbang = 1 For j = 1 To 8 Step 7 '1=decreasing, 8=increasing

hakbang = hakbang * -1

kl = kolum kr = kurow

If i = 0 Then

mlimit = kl Else

mlimit = kr

End If pwesto_ng_kalaban = alamin_ang_pwesto(kl, kr)

Do Until mlimit = j + hakbang Or block(pwesto_ng_kalaban) = 1

pwesto_ng_kalaban = alamin_ang_pwesto(kl, kr)

If i = 0 Then kl = kl + hakbang

mlimit = kl

Else kr = kr + hakbang

mlimit = kr

End If If local_pos <> pwesto_ng_kalaban Then

If (is_black_piece(pwesto_ng_kalaban, 0) Or

block(pwesto_ng_kalaban) = 0) Then If checked And naharangan_ba(pwesto_ng_kalaban) Then

checkmate_ba = False

GoTo end_checkmate_ba End If

End If

End If Loop

Next j

Next i

'************

'* diagonal *

'************ For i = 7 To 9 Step 2 ' 7=downward , 9=upward

For j = local_pos - i To 1 Step -i 'towards left

If (block(j) = 0 Or is_black_piece(j, 0)) And Image1(local_pos).Tag = Image1(j).Tag Then

If checked And naharangan_ba(j) Then

checkmate_ba = False GoTo end_checkmate_ba

End If

End If If block(j) = 1 Then

j = 1

End If Next j

For j = local_pos + i To 64 Step i 'towards right

If (block(j) = 0 Or is_black_piece(j, 0)) And Image1(local_pos).Tag = Image1(j).Tag Then

If checked And naharangan_ba(j) Then

checkmate_ba = False

Page 55: PC-Based Electronic Chess Board Game

Appendix D D-6

GoTo end_checkmate_ba

End If End If

If block(j) = 1 Then

j = 64 End If

Next j

Next i End If

Case "K"

'************* '* left side *

'*************

If kolum <= 8 And kolum > 1 Then pwesto_ng_kalaban = alamin_ang_pwesto(kolum - 1, kurow)

If (block(pwesto_ng_kalaban) = 0 Or

is_black_piece(pwesto_ng_kalaban, 0)) And Not square_on_threat(pwesto_ng_kalaban) Then

checkmate_ba = False

GoTo end_checkmate_ba End If

End If

'************** '* right side *

'**************

If kolum < 8 And kolum >= 1 Then pwesto_ng_kalaban = alamin_ang_pwesto(kolum + 1,

kurow) If (block(pwesto_ng_kalaban) = 0 Or

is_black_piece(pwesto_ng_kalaban, 0)) And Not

square_on_threat(pwesto_ng_kalaban) Then checkmate_ba = False

GoTo end_checkmate_ba

End If End If

'*********

'* above * '*********

If kurow <= 8 And kurow > 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum, kurow - 1) If (block(pwesto_ng_kalaban) = 0 Or

is_black_piece(pwesto_ng_kalaban, 0)) And Not

square_on_threat(pwesto_ng_kalaban) Then checkmate_ba = False

GoTo end_checkmate_ba

End If End If

'*********

'* below *

'*********

If kurow < 8 And kurow >= 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum, kurow + 1)

If (block(pwesto_ng_kalaban) = 0 Or

is_black_piece(pwesto_ng_kalaban, 0)) And Not square_on_threat(pwesto_ng_kalaban) Then

checkmate_ba = False

GoTo end_checkmate_ba End If

End If

'************ '* top left *

'************

If kolum <= 8 And kolum > 1 And kurow <= 8 And kurow > 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum - 1, kurow

- 1) If (block(pwesto_ng_kalaban) = 0 Or

is_black_piece(pwesto_ng_kalaban, 0)) And Not

square_on_threat(pwesto_ng_kalaban) Then

checkmate_ba = False

GoTo end_checkmate_ba End If

End If

'************* '* top right *

'*************

If kolum < 8 And kolum >= 1 And kurow <= 8 And kurow > 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum + 1, kurow

- 1) If (block(pwesto_ng_kalaban) = 0 Or

is_black_piece(pwesto_ng_kalaban, 0)) And Not

square_on_threat(pwesto_ng_kalaban) Then checkmate_ba = False

GoTo end_checkmate_ba

End If End If

'***************

'* bottom left * '***************

If kolum <= 8 And kolum > 1 And kurow < 8 And kurow >=

1 Then pwesto_ng_kalaban = alamin_ang_pwesto(kolum - 1, kurow

+ 1)

If (block(pwesto_ng_kalaban) = 0 Or is_black_piece(pwesto_ng_kalaban, 0)) And Not

square_on_threat(pwesto_ng_kalaban) Then checkmate_ba = False

GoTo end_checkmate_ba

End If End If

'****************

'* bottom right * '****************

If kolum < 8 And kolum >= 1 And kurow < 8 And kurow >=

1 Then pwesto_ng_kalaban = alamin_ang_pwesto(kolum + 1, kurow

+ 1)

If (block(pwesto_ng_kalaban) = 0 Or is_black_piece(pwesto_ng_kalaban, 0)) And Not

square_on_threat(pwesto_ng_kalaban) Then

checkmate_ba = False GoTo end_checkmate_ba

End If

End If End Select

End If 'white piece

End If 'white turn

'********

'* ITIM * '********

If blackturn Then

If is_black_piece(local_pos, 0) Then piecete = Image7(black_piece).Tag

Select Case piecete

Case "P" If Not blocked Then

If kurow = 2 Then

loops = 2 Else

loops = 1

End If For i = 1 To loops

If block(local_pos + i) = 0 Then

If checked And naharangan_ba(local_pos + 1) Then checkmate_ba = False

GoTo end_checkmate_ba

End If

Page 56: PC-Based Electronic Chess Board Game

Appendix D D-7

End If

Next End If

For j = 1 To -1 Step -2

If kolum + j <= 8 And kolum + j >= 1 And kurow < 8 Then pwesto_ng_kalaban = alamin_ang_pwesto(kolum + j, kurow

+ 1)

If is_white_piece(pwesto_ng_kalaban, 0) Then If checked And naharangan_ba(pwesto_ng_kalaban) Then

checkmate_ba = False

GoTo end_checkmate_ba End If

End If

End If Next j

'***************

'* passed pawn * '***************

For j = 1 To -1 Step -2

If kolum + j <= 8 And kolum + j >= 1 And kurow < 8 Then pwesto_ng_kalaban = alamin_ang_pwesto(kolum + j, kurow)

If is_white_piece(pwesto_ng_kalaban, 1) And

mpassed_pawn <> 0 Then If enpassantpiecew(mpassed_pawn) Then

If checked And naharangan_ba(pwesto_ng_kalaban) Then

checkmate_ba = False GoTo end_checkmate_ba

End If End If

End If

End If Next j

'**********

'* kabayo * '**********

Case "N"

If Not blocked Then For i = 0 To 7

Select Case i

Case 0, 5 kl = -1

Case 1, 4

kl = 1 Case 2, 3

kl = 2

Case 6, 7 kl = -2

End Select

Select Case i

Case 0, 1

kr = -2

Case 2, 7 kr = -1

Case 3, 6

kr = 1 Case 4, 5

kr = 2

End Select If (kolum + kl) <= 8 And (kolum + kl) >= 1 And (kurow +

kr) <= 8 And (kurow + kr) >= 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum + kl, kurow + kr)

If is_white_piece(pwesto_ng_kalaban, 0) Or

block(pwesto_ng_kalaban) = 0 Then If checked And naharangan_ba(pwesto_ng_kalaban) Then

checkmate_ba = False

GoTo end_checkmate_ba End If

End If

End If

Next i

End If 'not blocked '********

'* tore *

'******** Case "R"

If Not blocked Then

For i = 0 To 1 '0=horizontal, 1=vertical hakbang = 1

For j = 1 To 8 Step 7 '1=decreasing, 8=increasing

hakbang = hakbang * -1 kl = kolum

kr = kurow

If i = 0 Then mlimit = kl

Else

mlimit = kr End If

pwesto_ng_kalaban = alamin_ang_pwesto(kl, kr)

Do Until mlimit = j + hakbang Or block(pwesto_ng_kalaban) = 1

pwesto_ng_kalaban = alamin_ang_pwesto(kl, kr)

If i = 0 Then kl = kl + hakbang

mlimit = kl

Else kr = kr + hakbang

mlimit = kr End If

If local_pos <> pwesto_ng_kalaban Then

If (is_white_piece(pwesto_ng_kalaban, 0) Or block(pwesto_ng_kalaban) = 0) Then

If checked And naharangan_ba(pwesto_ng_kalaban) Then

checkmate_ba = False GoTo end_checkmate_ba

End If

End If End If

Loop

Next j Next i

End If

'********** '* bishop *

'**********

Case "B" If Not blocked Then

'************

'* diagonal *

'************

For i = 7 To 9 Step 2 ' 7=downward , 9=upward

For j = local_pos - i To 1 Step -i 'towards left If (block(j) = 0 Or is_white_piece(j, 0)) And

Image1(local_pos).Tag = Image1(j).Tag Then

If checked And naharangan_ba(j) Then checkmate_ba = False

GoTo end_checkmate_ba

End If End If

If block(j) = 1 Then

j = 1 End If

Next j

For j = local_pos + i To 64 Step i 'towards right If (block(j) = 0 Or is_white_piece(j, 0)) And

Image1(local_pos).Tag = Image1(j).Tag Then

If checked And naharangan_ba(j) Then checkmate_ba = False

GoTo end_checkmate_ba

End If

Page 57: PC-Based Electronic Chess Board Game

Appendix D D-8

End If

If block(j) = 1 Then j = 64

End If

Next j Next i

End If

'********* '* reyna *

'*********

Case "Q" If Not blocked Then

For i = 0 To 1 '0=horizontal, 1=vertical

hakbang = 1 For j = 1 To 8 Step 7 '1=decreasing, 8=increasing

hakbang = hakbang * -1

kl = kolum kr = kurow

If i = 0 Then

mlimit = kl Else

mlimit = kr

End If pwesto_ng_kalaban = alamin_ang_pwesto(kl, kr)

Do Until mlimit = j + hakbang Or block(pwesto_ng_kalaban)

= 1 pwesto_ng_kalaban = alamin_ang_pwesto(kl, kr)

If i = 0 Then kl = kl + hakbang

mlimit = kl

Else kr = kr + hakbang

mlimit = kr

End If If local_pos <> pwesto_ng_kalaban Then

If (is_white_piece(pwesto_ng_kalaban, 0) Or

block(pwesto_ng_kalaban) = 0) Then If checked And naharangan_ba(pwesto_ng_kalaban) Then

checkmate_ba = False

GoTo end_checkmate_ba End If

End If

End If Loop

Next j

Next i '************

'* diagonal *

'************

For i = 7 To 9 Step 2 ' 7=downward , 9=upward

For j = local_pos - i To 1 Step -i 'towards left

If (block(j) = 0 Or is_white_piece(j, 0)) And Image1(local_pos).Tag = Image1(j).Tag Then

If checked And naharangan_ba(j) Then

checkmate_ba = False GoTo end_checkmate_ba

End If

End If If block(j) = 1 Then

j = 1

End If Next j

For j = local_pos + i To 64 Step i 'towards right

If (block(j) = 0 Or is_white_piece(j, 0)) And Image1(local_pos).Tag = Image1(j).Tag Then

If checked And naharangan_ba(j) Then

checkmate_ba = False GoTo end_checkmate_ba

End If

End If

If block(j) = 1 Then

j = 64 End If

Next j

Next i End If

Case "K"

'************* '* left side *

'*************

If kolum <= 8 And kolum > 1 Then pwesto_ng_kalaban = alamin_ang_pwesto(kolum - 1, kurow)

If (block(pwesto_ng_kalaban) = 0 Or

is_white_piece(pwesto_ng_kalaban, 0)) And Not square_on_threat(pwesto_ng_kalaban) Then

checkmate_ba = False

GoTo end_checkmate_ba End If

End If

'************** '* right side *

'**************

If kolum < 8 And kolum >= 1 Then pwesto_ng_kalaban = alamin_ang_pwesto(kolum + 1,

kurow)

If (block(pwesto_ng_kalaban) = 0 Or is_white_piece(pwesto_ng_kalaban, 0)) And Not

square_on_threat(pwesto_ng_kalaban) Then checkmate_ba = False

GoTo end_checkmate_ba

End If End If

'*********

'* above * '*********

If kurow <= 8 And kurow > 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum, kurow - 1) If (block(pwesto_ng_kalaban) = 0 Or

is_white_piece(pwesto_ng_kalaban, 0)) And Not

square_on_threat(pwesto_ng_kalaban) Then checkmate_ba = False

GoTo end_checkmate_ba

End If End If

'*********

'* below * '*********

If kurow < 8 And kurow >= 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum, kurow +

1)

If (block(pwesto_ng_kalaban) = 0 Or

is_white_piece(pwesto_ng_kalaban, 0)) And Not square_on_threat(pwesto_ng_kalaban) Then

checkmate_ba = False

GoTo end_checkmate_ba End If

End If

'************ '* top left *

'************

If kolum <= 8 And kolum > 1 And kurow <= 8 And kurow > 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum - 1, kurow

- 1) If (block(pwesto_ng_kalaban) = 0 Or

is_white_piece(pwesto_ng_kalaban, 0)) And Not

square_on_threat(pwesto_ng_kalaban) Then checkmate_ba = False

GoTo end_checkmate_ba

End If

Page 58: PC-Based Electronic Chess Board Game

Appendix D D-9

End If

'************* '* top right *

'*************

If kolum < 8 And kolum >= 1 And kurow <= 8 And kurow > 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum + 1, kurow

- 1) If (block(pwesto_ng_kalaban) = 0 Or

is_white_piece(pwesto_ng_kalaban, 0)) And Not

square_on_threat(pwesto_ng_kalaban) Then checkmate_ba = False

GoTo end_checkmate_ba

End If End If

'***************

'* bottom left * '***************

If kolum <= 8 And kolum > 1 And kurow < 8 And kurow >=

1 Then pwesto_ng_kalaban = alamin_ang_pwesto(kolum - 1, kurow

+ 1)

If (block(pwesto_ng_kalaban) = 0 Or is_white_piece(pwesto_ng_kalaban, 0)) And Not

square_on_threat(pwesto_ng_kalaban) Then

checkmate_ba = False GoTo end_checkmate_ba

End If End If

'****************

'* bottom right * '****************

If kolum < 8 And kolum >= 1 And kurow < 8 And kurow >=

1 Then pwesto_ng_kalaban = alamin_ang_pwesto(kolum + 1, kurow

+ 1)

If (block(pwesto_ng_kalaban) = 0 Or is_white_piece(pwesto_ng_kalaban, 0)) And Not

square_on_threat(pwesto_ng_kalaban) Then

checkmate_ba = False GoTo end_checkmate_ba

End If

End If End Select

End If

End If 'black turn Next local_pos

end_checkmate_ba:

checkmate = checkmate_ba

End Function

Private Function glow_tile() Dim kolum As Integer, kurow As Integer, loops As Integer,

pwesto_ng_kalaban As Integer, mlimit As Integer

Dim i As Integer, j As Integer, start As Integer, hakbang As Integer, uno As Integer, dos As Integer

Dim kl As Integer, kr As Integer

kolum = what_column(position) kurow = what_row(position)

If whiteturn Then

Select Case piece Case "P"

'*********************

'* walang nakaharang * '*********************

If Not blocked Then

If kurow = 7 Then loops = 2

Else

loops = 1

End If

For i = 1 To loops If block(position - i) = 0 Or ((Not is_white_piece(position -

1, 0)) And (Not is_black_piece(position - 1, 0))) Then

If checked Then If naharangan_ba(position - i) Then

lit_on (position - i)

End If Else

If OpenCheckTilesCount = 0 Then

lit_on (position - i) Else

If OnOpenCheckTiles(position - i) Then

lit_on (position - i) End If

End If

End If End If

Next

End If 'not blocked '****************

'* may makakain *

'**************** For j = 1 To -1 Step -2

If kolum + j <= 8 And kolum + j >= 1 And kurow > 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum + j, kurow - 1)

If is_black_piece(pwesto_ng_kalaban, 0) Then If checked Then

If naharangan_ba(pwesto_ng_kalaban) Then

lit_on (pwesto_ng_kalaban) End If

Else

If OpenCheckTilesCount = 0 Then lit_on (pwesto_ng_kalaban)

Else

If OnOpenCheckTiles(pwesto_ng_kalaban) Then lit_on (pwesto_ng_kalaban)

End If

End If End If

End If

End If Next j

'***************

'* passed pawn * '***************

For j = 1 To -1 Step -2

If kolum + j <= 8 And kolum + j >= 1 And kurow > 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum + j, kurow)

If is_black_piece(pwesto_ng_kalaban, 1) And

mpassed_pawn <> 0 Then If enpassantpieceb(mpassed_pawn) Then

If checked Then

If naharangan_ba(pwesto_ng_kalaban - 1) Then lit_on (pwesto_ng_kalaban - 1)

End If

Else If OpenCheckTilesCount = 0 Then

lit_on (pwesto_ng_kalaban - 1)

Else If OnOpenCheckTiles(pwesto_ng_kalaban - 1) Then

lit_on (pwesto_ng_kalaban - 1)

End If End If

End If

End If End If

End If

Next j

Page 59: PC-Based Electronic Chess Board Game

Appendix D D-10

'**********

'* kabayo * '**********

Case "N"

If Not blocked Then For i = 0 To 7

Select Case i

Case 0, 5 kl = -1

Case 1, 4

kl = 1 Case 2, 3

kl = 2

Case 6, 7 kl = -2

End Select

Select Case i Case 0, 1

kr = -2

Case 2, 7 kr = -1

Case 3, 6

kr = 1 Case 4, 5

kr = 2

End Select If (kolum + kl) <= 8 And (kolum + kl) >= 1 And (kurow +

kr) <= 8 And (kurow + kr) >= 1 Then pwesto_ng_kalaban = alamin_ang_pwesto(kolum + kl,

kurow + kr)

If is_black_piece(pwesto_ng_kalaban, 0) Or block(pwesto_ng_kalaban) = 0 Or (Not

is_white_piece(pwesto_ng_kalaban, 0)) Then

If checked Then If naharangan_ba(pwesto_ng_kalaban) Then

lit_on (pwesto_ng_kalaban)

End If Else

lit_on (pwesto_ng_kalaban)

End If End If

End If

Next i End If 'not blocked

'********

'* tore * '********

Case "R"

If Not blocked Then

For i = 0 To 1 '0=horizontal, 1=vertical

hakbang = 1

For j = 1 To 8 Step 7 '1=decreasing, 8=increasing hakbang = hakbang * -1

kl = kolum

kr = kurow If i = 0 Then

mlimit = kl

Else mlimit = kr

End If

pwesto_ng_kalaban = alamin_ang_pwesto(kl, kr) Do Until mlimit = j + hakbang Or block(pwesto_ng_kalaban)

= 1

pwesto_ng_kalaban = alamin_ang_pwesto(kl, kr) If i = 0 Then

kl = kl + hakbang

mlimit = kl Else

kr = kr + hakbang

mlimit = kr

End If

If position <> pwesto_ng_kalaban Then If (is_black_piece(pwesto_ng_kalaban, 0) Or

block(pwesto_ng_kalaban) = 0) Or (Not

is_white_piece(pwesto_ng_kalaban, 0)) Then If checked Then

If naharangan_ba(pwesto_ng_kalaban) Then

lit_on (pwesto_ng_kalaban) End If

Else

If OpenCheckTilesCount = 0 Then lit_on (pwesto_ng_kalaban)

Else

If OnOpenCheckTiles(pwesto_ng_kalaban) Then lit_on (pwesto_ng_kalaban)

End If

End If End If

End If

End If Loop

Next j

Next i '*********************************************

'* disable castling on their side after move *

'********************************************* If piecenum = 16 Or mcastling = False Then

castling_king_side = False End If

If piecenum = 9 Or mcastling = False Then

castling_queen_side = False End If

End If

'********** '* bishop *

'**********

Case "B" If Not blocked Then

'************

'* diagonal * '************

For i = 7 To 9 Step 2 ' 7=downward , 9=upward

For j = position - i To 1 Step -i 'towards left If (block(j) = 0 Or is_black_piece(j, 0) Or (Not

is_white_piece(j, 0))) And Image1(position).Tag =

Image1(j).Tag Then If checked Then

If naharangan_ba(j) Then

lit_on (j)

End If

Else

If OpenCheckTilesCount = 0 Then lit_on (j)

Else

If OnOpenCheckTiles(j) Then lit_on (j)

End If

End If End If

End If

If block(j) = 1 Then j = 1

End If

Next j For j = position + i To 64 Step i 'towards right

If (block(j) = 0 Or is_black_piece(j, 0) Or (Not

is_white_piece(j, 0))) And Image1(position).Tag = Image1(j).Tag Then

If checked Then

If naharangan_ba(j) Then

Page 60: PC-Based Electronic Chess Board Game

Appendix D D-11

lit_on (j)

End If Else

If OpenCheckTilesCount = 0 Then

lit_on (j) Else

If OnOpenCheckTiles(j) Then

lit_on (j) End If

End If

End If End If

If block(j) = 1 Then

j = 64 End If

Next j

Next i End If 'blocked

'*********

'* reyna * '*********

Case "Q"

If Not blocked Then For i = 0 To 1 '0=horizontal, 1=vertical

hakbang = 1

For j = 1 To 8 Step 7 '1=decreasing, 8=increasing hakbang = hakbang * -1

kl = kolum kr = kurow

If i = 0 Then

mlimit = kl Else

mlimit = kr

End If pwesto_ng_kalaban = alamin_ang_pwesto(kl, kr)

Do Until mlimit = j + hakbang Or block(pwesto_ng_kalaban)

= 1 pwesto_ng_kalaban = alamin_ang_pwesto(kl, kr)

If i = 0 Then

kl = kl + hakbang mlimit = kl

Else

kr = kr + hakbang mlimit = kr

End If

If position <> pwesto_ng_kalaban Then If (is_black_piece(pwesto_ng_kalaban, 0) Or

block(pwesto_ng_kalaban) = 0) Or (Not

is_white_piece(pwesto_ng_kalaban, 0)) Then

If checked Then

If naharangan_ba(pwesto_ng_kalaban) Then

lit_on (pwesto_ng_kalaban) End If

Else

If OpenCheckTilesCount = 0 Then lit_on (pwesto_ng_kalaban)

Else

If OnOpenCheckTiles(pwesto_ng_kalaban) Then lit_on (pwesto_ng_kalaban)

End If

End If End If

End If

End If Loop

Next j

Next i '************

'* diagonal *

'************

For i = 7 To 9 Step 2 ' 7=downward , 9=upward

For j = position - i To 1 Step -i 'towards left If (block(j) = 0 Or is_black_piece(j, 0) Or (Not

is_white_piece(j, 0))) And Image1(position).Tag =

Image1(j).Tag Then If checked Then

If naharangan_ba(j) Then

lit_on (j) End If

Else

If OpenCheckTilesCount = 0 Then lit_on (j)

Else

If OnOpenCheckTiles(j) Then lit_on (j)

End If

End If End If

End If

If block(j) = 1 Then j = 1

End If

Next j For j = position + i To 64 Step i 'towards right

If (block(j) = 0 Or is_black_piece(j, 0) Or (Not

is_white_piece(j, 0))) And Image1(position).Tag = Image1(j).Tag Then

If checked Then If naharangan_ba(j) Then

lit_on (j)

End If Else

If OpenCheckTilesCount = 0 Then

lit_on (j) Else

If OnOpenCheckTiles(j) Then

lit_on (j) End If

End If

End If End If

If block(j) = 1 Then

j = 64 End If

Next j

Next i End If

'********

'* hari *

'********

Case "K"

If Not blocked Then '*************************************

'* left side / queen's side castling *

'************************************* If kolum <= 8 And kolum > 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum - 1, kurow)

If (block(pwesto_ng_kalaban) = 0 Or is_black_piece(pwesto_ng_kalaban, 0) Or (Not

is_white_piece(pwesto_ng_kalaban, 0))) And Not

square_on_threat(pwesto_ng_kalaban) Then lit_on (pwesto_ng_kalaban)

End If

If block(16) = 0 And block(24) = 0 And block(32) = 0 And (Not square_on_threat(24)) And (Not square_on_threat(32))

And (Not checked) And position = 40 And

castling_queen_side Then pwesto_ng_kalaban = alamin_ang_pwesto(kolum - 2, kurow)

lit_on (pwesto_ng_kalaban)

End If

Page 61: PC-Based Electronic Chess Board Game

Appendix D D-12

End If

'************************************* '* right side / king's side castling *

'*************************************

If kolum < 8 And kolum >= 1 Then pwesto_ng_kalaban = alamin_ang_pwesto(kolum + 1,

kurow)

If (block(pwesto_ng_kalaban) = 0 Or is_black_piece(pwesto_ng_kalaban, 0) Or (Not

is_white_piece(pwesto_ng_kalaban, 0))) And Not

square_on_threat(pwesto_ng_kalaban) Then lit_on (pwesto_ng_kalaban)

End If

If block(48) = 0 And block(56) = 0 And (Not square_on_threat(48)) And (Not square_on_threat(56)) And

(Not checked) And position = 40 And castling_king_side

Then pwesto_ng_kalaban = alamin_ang_pwesto(kolum + 2,

kurow)

lit_on (pwesto_ng_kalaban) End If

End If

'********* '* above *

'*********

If kurow <= 8 And kurow > 1 Then pwesto_ng_kalaban = alamin_ang_pwesto(kolum, kurow - 1)

If (block(pwesto_ng_kalaban) = 0 Or is_black_piece(pwesto_ng_kalaban, 0) Or (Not

is_white_piece(pwesto_ng_kalaban, 0))) And Not

square_on_threat(pwesto_ng_kalaban) Then lit_on (pwesto_ng_kalaban)

End If

End If '*********

'* below *

'********* If kurow < 8 And kurow >= 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum, kurow +

1) If (block(pwesto_ng_kalaban) = 0 Or

is_black_piece(pwesto_ng_kalaban, 0) Or (Not

is_white_piece(pwesto_ng_kalaban, 0))) And Not square_on_threat(pwesto_ng_kalaban) Then

lit_on (pwesto_ng_kalaban)

End If End If

'************

'* top left *

'************

If kolum <= 8 And kolum > 1 And kurow <= 8 And kurow >

1 Then pwesto_ng_kalaban = alamin_ang_pwesto(kolum - 1, kurow

- 1)

If (block(pwesto_ng_kalaban) = 0 Or is_black_piece(pwesto_ng_kalaban, 0) Or (Not

is_white_piece(pwesto_ng_kalaban, 0))) And Not

square_on_threat(pwesto_ng_kalaban) Then lit_on (pwesto_ng_kalaban)

End If

End If '*************

'* top right *

'************* If kolum < 8 And kolum >= 1 And kurow <= 8 And kurow >

1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum + 1, kurow - 1)

If (block(pwesto_ng_kalaban) = 0 Or

is_black_piece(pwesto_ng_kalaban, 0) Or (Not

is_white_piece(pwesto_ng_kalaban, 0))) And Not

square_on_threat(pwesto_ng_kalaban) Then lit_on (pwesto_ng_kalaban)

End If

End If '***************

'* bottom left *

'*************** If kolum <= 8 And kolum > 1 And kurow < 8 And kurow >=

1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum - 1, kurow + 1)

If (block(pwesto_ng_kalaban) = 0 Or

is_black_piece(pwesto_ng_kalaban, 0) Or (Not is_white_piece(pwesto_ng_kalaban, 0))) And Not

square_on_threat(pwesto_ng_kalaban) Then

lit_on (pwesto_ng_kalaban) End If

End If

'**************** '* bottom right *

'****************

If kolum < 8 And kolum >= 1 And kurow < 8 And kurow >= 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum + 1, kurow

+ 1) If (block(pwesto_ng_kalaban) = 0 Or

is_black_piece(pwesto_ng_kalaban, 0) Or (Not is_white_piece(pwesto_ng_kalaban, 0))) And Not

square_on_threat(pwesto_ng_kalaban) Then

lit_on (pwesto_ng_kalaban) End If

End If

mcastling = False End If

'case wala na

End Select End If 'white turn

'-------------------------------------------------

'******** '* ITIM *

'********

If blackturn Then Select Case piece

Case "P"

If Not blocked Then If kurow = 2 Then

loops = 2

Else

loops = 1

End If

For i = 1 To loops If block(position + i) = 0 Or (Not is_black_piece(position + i,

0)) Or (Not is_white_piece(position + i, 0)) Then

If checked Then If naharangan_ba(position + 1) Then

lit_on (position + i)

End If Else

If OpenCheckTilesCount = 0 Then

lit_on (position + i) Else

If OnOpenCheckTiles(position + i) Then

lit_on (position + i) End If

End If

End If End If

Next

End If

Page 62: PC-Based Electronic Chess Board Game

Appendix D D-13

For j = 1 To -1 Step -2

If kolum + j <= 8 And kolum + j >= 1 And kurow < 8 Then pwesto_ng_kalaban = alamin_ang_pwesto(kolum + j, kurow

+ 1)

If is_white_piece(pwesto_ng_kalaban, 0) Then If checked Then

If naharangan_ba(pwesto_ng_kalaban) Then

lit_on (pwesto_ng_kalaban) End If

Else

If OpenCheckTilesCount = 0 Then lit_on (pwesto_ng_kalaban)

Else

If OnOpenCheckTiles(pwesto_ng_kalaban) Then lit_on (pwesto_ng_kalaban)

End If

End If End If

End If

End If Next j

'***************

'* passed pawn * '***************

For j = 1 To -1 Step -2

If kolum + j <= 8 And kolum + j >= 1 And kurow < 8 Then pwesto_ng_kalaban = alamin_ang_pwesto(kolum + j, kurow)

If is_white_piece(pwesto_ng_kalaban, 1) And mpassed_pawn <> 0 Then

If enpassantpiecew(mpassed_pawn) Then

If checked Then If naharangan_ba(pwesto_ng_kalaban + 1) Then

lit_on (pwesto_ng_kalaban + 1)

End If Else

If OpenCheckTilesCount = 0 Then

lit_on (pwesto_ng_kalaban + 1) Else

If OnOpenCheckTiles(pwesto_ng_kalaban + 1) Then

lit_on (pwesto_ng_kalaban + 1) End If

End If

End If End If

End If

End If Next j

'**********

'* kabayo *

'**********

Case "N"

If Not blocked Then For i = 0 To 7

Select Case i

Case 0, 5 kl = -1

Case 1, 4

kl = 1 Case 2, 3

kl = 2

Case 6, 7 kl = -2

End Select

Select Case i Case 0, 1

kr = -2

Case 2, 7 kr = -1

Case 3, 6

kr = 1

Case 4, 5

kr = 2 End Select

If (kolum + kl) <= 8 And (kolum + kl) >= 1 And (kurow +

kr) <= 8 And (kurow + kr) >= 1 Then pwesto_ng_kalaban = alamin_ang_pwesto(kolum + kl,

kurow + kr)

If is_white_piece(pwesto_ng_kalaban, 0) Or block(pwesto_ng_kalaban) = 0 Or (Not

is_black_piece(pwesto_ng_kalaban, 0)) Then

If checked Then If naharangan_ba(pwesto_ng_kalaban) Then

lit_on (pwesto_ng_kalaban)

End If Else

lit_on (pwesto_ng_kalaban)

End If End If

End If

Next i End If 'not blocked

'********

'* tore * '********

Case "R"

If Not blocked Then For i = 0 To 1 '0=horizontal, 1=vertical

hakbang = 1 For j = 1 To 8 Step 7 '1=decreasing, 8=increasing

hakbang = hakbang * -1

kl = kolum kr = kurow

If i = 0 Then

mlimit = kl Else

mlimit = kr

End If pwesto_ng_kalaban = alamin_ang_pwesto(kl, kr)

Do Until mlimit = j + hakbang Or block(pwesto_ng_kalaban)

= 1 pwesto_ng_kalaban = alamin_ang_pwesto(kl, kr)

If i = 0 Then

kl = kl + hakbang mlimit = kl

Else

kr = kr + hakbang mlimit = kr

End If

If position <> pwesto_ng_kalaban Then

If (is_white_piece(pwesto_ng_kalaban, 0) Or

block(pwesto_ng_kalaban) = 0) Or (Not

is_black_piece(pwesto_ng_kalaban, 0)) Then If checked Then

If naharangan_ba(pwesto_ng_kalaban) Then

lit_on (pwesto_ng_kalaban) End If

Else

If OpenCheckTilesCount = 0 Then lit_on (pwesto_ng_kalaban)

Else

If OnOpenCheckTiles(pwesto_ng_kalaban) Then lit_on (pwesto_ng_kalaban)

End If

End If End If

End If

End If Loop

Next j

Next i

Page 63: PC-Based Electronic Chess Board Game

Appendix D D-14

'*********************************************

'* disable castling on their side after move * '*********************************************

If piecenum = 16 Or mcastlingb = False Then

castling_king_sideb = False End If

If piecenum = 9 Or mcastlingb = False Then

castling_queen_sideb = False End If

End If

'********** '* bishop *

'**********

Case "B" If Not blocked Then

'************

'* diagonal * '************

For i = 7 To 9 Step 2 ' 7=downward , 9=upward

For j = position - i To 1 Step -i 'towards left If (block(j) = 0 Or is_white_piece(j, 0) Or (Not

is_black_piece(j, 0))) And Image1(position).Tag =

Image1(j).Tag Then If checked Then

If naharangan_ba(j) Then

lit_on (j) End If

Else If OpenCheckTilesCount = 0 Then

lit_on (j)

Else If OnOpenCheckTiles(j) Then

lit_on (j)

End If End If

End If

End If If block(j) = 1 Then

j = 1

End If Next j

For j = position + i To 64 Step i 'towards right

If (block(j) = 0 Or is_white_piece(j, 0) Or (Not is_black_piece(j, 0))) And Image1(position).Tag =

Image1(j).Tag Then

If checked Then If naharangan_ba(j) Then

lit_on (j)

End If

Else

If OpenCheckTilesCount = 0 Then

lit_on (j) Else

If OnOpenCheckTiles(j) Then

lit_on (j) End If

End If

End If End If

If block(j) = 1 Then

j = 64 End If

Next j

Next i End If

'*********

'* reyna * '*********

Case "Q"

If Not blocked Then

For i = 0 To 1 '0=horizontal, 1=vertical

hakbang = 1 For j = 1 To 8 Step 7 '1=decreasing, 8=increasing

hakbang = hakbang * -1

kl = kolum kr = kurow

If i = 0 Then

mlimit = kl Else

mlimit = kr

End If pwesto_ng_kalaban = alamin_ang_pwesto(kl, kr)

Do Until mlimit = j + hakbang Or block(pwesto_ng_kalaban)

= 1 pwesto_ng_kalaban = alamin_ang_pwesto(kl, kr)

If i = 0 Then

kl = kl + hakbang mlimit = kl

Else

kr = kr + hakbang mlimit = kr

End If

If position <> pwesto_ng_kalaban Then If (is_white_piece(pwesto_ng_kalaban, 0) Or

block(pwesto_ng_kalaban) = 0) Or (Not

is_black_piece(pwesto_ng_kalaban, 0)) Then If checked Then

If naharangan_ba(pwesto_ng_kalaban) Then lit_on (pwesto_ng_kalaban)

End If

Else If OpenCheckTilesCount = 0 Then

lit_on (pwesto_ng_kalaban)

Else If OnOpenCheckTiles(pwesto_ng_kalaban) Then

lit_on (pwesto_ng_kalaban)

End If End If

End If

End If End If

Loop

Next j Next i

'************

'* diagonal * '************

For i = 7 To 9 Step 2 ' 7=downward , 9=upward

For j = position - i To 1 Step -i 'towards left

If (block(j) = 0 Or is_white_piece(j, 0) Or (Not

is_black_piece(j, 0))) And Image1(position).Tag =

Image1(j).Tag Then If checked Then

If naharangan_ba(j) Then

lit_on (j) End If

Else

If OpenCheckTilesCount = 0 Then lit_on (j)

Else

If OnOpenCheckTiles(j) Then lit_on (j)

End If

End If End If

End If

If block(j) = 1 Then j = 1

End If

Next j

Page 64: PC-Based Electronic Chess Board Game

Appendix D D-15

For j = position + i To 64 Step i 'towards right

If (block(j) = 0 Or is_white_piece(j, 0) Or (Not is_black_piece(j, 0))) And Image1(position).Tag =

Image1(j).Tag Then

If checked Then If naharangan_ba(j) Then

lit_on (j)

End If Else

If OpenCheckTilesCount = 0 Then

lit_on (j) Else

If OnOpenCheckTiles(j) Then

lit_on (j) End If

End If

End If End If

If block(j) = 1 Then

j = 64 End If

Next j

Next i End If

'********

'* hari * '********

Case "K" If Not blocked Then

'*************************************

'* left side / queen's side castling * '*************************************

If kolum <= 8 And kolum > 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum - 1, kurow) If (block(pwesto_ng_kalaban) = 0 Or

is_white_piece(pwesto_ng_kalaban, 0) Or (Not

is_black_piece(pwesto_ng_kalaban, 0))) And Not square_on_threat(pwesto_ng_kalaban) Then

lit_on (pwesto_ng_kalaban)

End If If block(9) = 0 And block(17) = 0 And block(25) = 0 And

(Not square_on_threat(17)) And (Not square_on_threat(25))

And (Not checked) And position = 33 And castling_queen_sideb Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum - 2, kurow)

lit_on (pwesto_ng_kalaban) End If

End If

'*************************************

'* right side / king's side castling *

'*************************************

If kolum < 8 And kolum >= 1 Then pwesto_ng_kalaban = alamin_ang_pwesto(kolum + 1,

kurow)

If (block(pwesto_ng_kalaban) = 0 Or is_white_piece(pwesto_ng_kalaban, 0) Or (Not

is_black_piece(pwesto_ng_kalaban, 0))) And Not

square_on_threat(pwesto_ng_kalaban) Then lit_on (pwesto_ng_kalaban)

End If

If block(41) = 0 And block(49) = 0 And (Not square_on_threat(41)) And (Not square_on_threat(49)) And

(Not checked) And position = 33 And castling_king_sideb

Then pwesto_ng_kalaban = alamin_ang_pwesto(kolum + 2,

kurow)

lit_on (pwesto_ng_kalaban) End If

End If

'*********

'* above *

'********* If kurow <= 8 And kurow > 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum, kurow - 1)

If (block(pwesto_ng_kalaban) = 0 Or is_white_piece(pwesto_ng_kalaban, 0) Or (Not

is_black_piece(pwesto_ng_kalaban, 0))) And Not

square_on_threat(pwesto_ng_kalaban) Then lit_on (pwesto_ng_kalaban)

End If

End If '*********

'* below *

'********* If kurow < 8 And kurow >= 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum, kurow +

1) If (block(pwesto_ng_kalaban) = 0 Or

is_white_piece(pwesto_ng_kalaban, 0) Or (Not

is_black_piece(pwesto_ng_kalaban, 0))) And Not square_on_threat(pwesto_ng_kalaban) Then

lit_on (pwesto_ng_kalaban)

End If End If

'************

'* top left * '************

If kolum <= 8 And kolum > 1 And kurow <= 8 And kurow > 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum - 1, kurow

- 1) If (block(pwesto_ng_kalaban) = 0 Or

is_white_piece(pwesto_ng_kalaban, 0) Or (Not

is_black_piece(pwesto_ng_kalaban, 0))) And Not square_on_threat(pwesto_ng_kalaban) Then

lit_on (pwesto_ng_kalaban)

End If End If

'*************

'* top right * '*************

If kolum < 8 And kolum >= 1 And kurow <= 8 And kurow >

1 Then pwesto_ng_kalaban = alamin_ang_pwesto(kolum + 1, kurow

- 1)

If (block(pwesto_ng_kalaban) = 0 Or is_white_piece(pwesto_ng_kalaban, 0) Or (Not

is_black_piece(pwesto_ng_kalaban, 0))) And Not

square_on_threat(pwesto_ng_kalaban) Then

lit_on (pwesto_ng_kalaban)

End If

End If '***************

'* bottom left *

'*************** If kolum <= 8 And kolum > 1 And kurow < 8 And kurow >=

1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum - 1, kurow + 1)

If (block(pwesto_ng_kalaban) = 0 Or

is_white_piece(pwesto_ng_kalaban, 0) Or (Not is_black_piece(pwesto_ng_kalaban, 0))) And Not

square_on_threat(pwesto_ng_kalaban) Then

lit_on (pwesto_ng_kalaban) End If

End If

'**************** '* bottom right *

'****************

Page 65: PC-Based Electronic Chess Board Game

Appendix D D-16

If kolum < 8 And kolum >= 1 And kurow < 8 And kurow >=

1 Then pwesto_ng_kalaban = alamin_ang_pwesto(kolum + 1, kurow

+ 1)

If (block(pwesto_ng_kalaban) = 0 Or is_white_piece(pwesto_ng_kalaban, 0) Or (Not

is_black_piece(pwesto_ng_kalaban, 0))) And Not

square_on_threat(pwesto_ng_kalaban) Then lit_on (pwesto_ng_kalaban)

End If

End If mcastlingb = False

End If

'case wala na End Select

End If 'black turn

End Function

Private Function inc_blocks(square As Integer)

sqctr = sqctr + 1 squares_to_be_blocked(sqctr) = square

End Function

Private Function inc_changed_tiles(pos As Integer)

changed_tiles_count = changed_tiles_count + 1

changed_tiles(changed_tiles_count) = pos End Function

Private Function is_black_piece(square_number As Integer, pawn As Integer) As Boolean

Dim limit As Integer

is_black_piece = False If pawn = 0 Then

limit = 16

Else limit = 8

End If

For i = 1 To limit If Image7(i).Top = Image1(square_number).Top And

Image7(i).Left = Image1(square_number).Left And

block(square_number) = 1 Then is_black_piece = True

mpassed_pawn = i

black_piece = i i = limit

End If

Next i End Function

Private Function is_white_piece(square_number As Integer,

pawn As Integer) As Boolean

Dim limit As Integer

is_white_piece = False

If pawn = 0 Then limit = 16

Else

limit = 8 End If

For i = 1 To limit

If Image6(i).Top = Image1(square_number).Top And Image6(i).Left = Image1(square_number).Left And

block(square_number) = 1 Then

is_white_piece = True mpassed_pawn = i

white_piece = i

i = limit End If

Next i

End Function Private Function led_array_out()

Dim x As Integer

For i = 1 To 8

Out 890, 42 'sets the led array timer to high

x = 1 For j = 1 To 8

If led_array(j * i) = 1 Then

led_column(i) = led_column(i) + x End If

x = x * 2

Next j Out 888, led_column(i) 'output the status of the LEDs to the

data port

led_column(i) = 0 Out 890, 34 'sets the led array timer to low

Next i

End Function Private Function lit_off(pwesto As Integer)

If Image1(pwesto).Tag = "white" Then

Image1(pwesto).Picture = LoadPicture(App.Path & "/images/white.jpg")

End If

If Image1(pwesto).Tag = "black" Then Image1(pwesto).Picture = LoadPicture(App.Path &

"/images/black.jpg")

End If led_array(pwesto) = 0

End Function

Private Function lit_on(pwesto As Integer) If block(pwesto) = 0 Then

Image1(pwesto).Picture = LoadPicture(App.Path & "/images/white_glow.jpg")

End If

If block(pwesto) = 1 Then Image1(pwesto).Picture = LoadPicture(App.Path &

"/images/black_glow.jpg")

End If led_array(pwesto) = 1

changed_tiles_count = changed_tiles_count + 1

changed_tiles(changed_tiles_count) = pwesto End Function

Private Function may_threat(pwesto As Integer)

Image1(pwesto).Picture = LoadPicture(App.Path & "/images/on_threat.jpg")

led_array(pwesto) = 1

changed_tiles_count = changed_tiles_count + 1 changed_tiles(changed_tiles_count) = pwesto

End Function

Private Function naharangan_ba(square_number As Integer) As Boolean

naharangan_ba = False

For i = 1 To sqctr

If square_number = squares_to_be_blocked(i) Then

naharangan_ba = True

i = sqctr End If

Next i

End Function Private Function nenah() As Boolean

Dim kolum As Integer, kurow As Integer, loops As Integer,

pwesto_ng_kalaban As Integer, mlimit As Integer Dim i As Integer, j As Integer, hakbang As Integer

Dim kl As Integer, kr As Integer

kolum = what_column(position) kurow = what_row(position)

nenah = False

If Not checked Then

nenah = True

GoTo end_nenah End If

If whiteturn Then

Page 66: PC-Based Electronic Chess Board Game

Appendix D D-17

Select Case piece

Case "P" '*********************

'* walang nakaharang *

'********************* If Not blocked Then

If kurow = 7 Then

loops = 2 Else

loops = 1

End If For i = 1 To loops

If block(position - i) = 0 Then

If checked And naharangan_ba(position - i) Then nenah = True

GoTo end_nenah

End If Else

i = loops

End If Next

End If 'not blocked

'**************** '* may makakain *

'****************

For j = 1 To -1 Step -2 If kolum + j <= 8 And kolum + j >= 1 And kurow > 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum + j, kurow - 1)

If is_black_piece(pwesto_ng_kalaban, 0) Then

If checked And naharangan_ba(pwesto_ng_kalaban) Then nenah = True

GoTo end_nenah

End If End If

End If

Next j '***************

'* passed pawn *

'*************** For j = 1 To -1 Step -2

If kolum + j <= 8 And kolum + j >= 1 And kurow > 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum + j, kurow) If is_black_piece(pwesto_ng_kalaban, 1) And

mpassed_pawn <> 0 Then

If enpassantpieceb(mpassed_pawn) Then If checked And naharangan_ba(pwesto_ng_kalaban) Then

nenah = True

GoTo end_nenah

End If

End If

End If End If

Next j

'********** '* kabayo *

'**********

Case "N" If Not blocked Then

For i = 0 To 7

Select Case i Case 0, 5

kl = -1

Case 1, 4 kl = 1

Case 2, 3

kl = 2 Case 6, 7

kl = -2

End Select

Select Case i

Case 0, 1 kr = -2

Case 2, 7

kr = -1 Case 3, 6

kr = 1

Case 4, 5 kr = 2

End Select

If (kolum + kl) <= 8 And (kolum + kl) >= 1 And (kurow + kr) <= 8 And (kurow + kr) >= 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum + kl,

kurow + kr) If is_black_piece(pwesto_ng_kalaban, 0) Or

block(pwesto_ng_kalaban) = 0 Then

If checked And naharangan_ba(pwesto_ng_kalaban) Then nenah = True

GoTo end_nenah

End If End If

End If

Next i End If 'not blocked

'********

'* tore * '********

Case "R" If Not blocked Then

For i = 0 To 1 '0=horizontal, 1=vertical

hakbang = 1 For j = 1 To 8 Step 7 '1=decreasing, 8=increasing

hakbang = hakbang * -1

kl = kolum kr = kurow

If i = 0 Then

mlimit = kl Else

mlimit = kr

End If pwesto_ng_kalaban = alamin_ang_pwesto(kl, kr)

Do Until mlimit = j + hakbang Or block(pwesto_ng_kalaban)

= 1 pwesto_ng_kalaban = alamin_ang_pwesto(kl, kr)

If i = 0 Then

kl = kl + hakbang mlimit = kl

Else

kr = kr + hakbang

mlimit = kr

End If

If position <> pwesto_ng_kalaban Then If (is_black_piece(pwesto_ng_kalaban, 0) Or

block(pwesto_ng_kalaban) = 0) Then

If checked And naharangan_ba(pwesto_ng_kalaban) Then nenah = True

GoTo end_nenah

End If End If

End If

Loop Next j

Next i

End If '**********

'* bishop *

'********** Case "B"

If Not blocked Then

'************

Page 67: PC-Based Electronic Chess Board Game

Appendix D D-18

'* diagonal *

'************ For i = 7 To 9 Step 2 ' 7=downward , 9=upward

For j = position - i To 1 Step -i 'towards left

If (block(j) = 0 Or is_black_piece(j, 0)) And Image1(position).Tag = Image1(j).Tag Then

If checked And naharangan_ba(j) Then

nenah = True GoTo end_nenah

End If

End If If block(j) = 1 Then

j = 1

End If Next j

For j = position + i To 64 Step i 'towards right

If (block(j) = 0 Or is_black_piece(j, 0)) And Image1(position).Tag = Image1(j).Tag Then

If checked And naharangan_ba(j) Then

nenah = True GoTo end_nenah

End If

End If If block(j) = 1 Then

j = 64

End If Next j

Next i End If 'blocked

'*********

'* reyna * '*********

Case "Q"

If Not blocked Then For i = 0 To 1 '0=horizontal, 1=vertical

hakbang = 1

For j = 1 To 8 Step 7 '1=decreasing, 8=increasing hakbang = hakbang * -1

kl = kolum

kr = kurow If i = 0 Then

mlimit = kl

Else mlimit = kr

End If

pwesto_ng_kalaban = alamin_ang_pwesto(kl, kr) Do Until mlimit = j + hakbang Or block(pwesto_ng_kalaban)

= 1

pwesto_ng_kalaban = alamin_ang_pwesto(kl, kr)

If i = 0 Then

kl = kl + hakbang

mlimit = kl Else

kr = kr + hakbang

mlimit = kr End If

If position <> pwesto_ng_kalaban Then

If (is_black_piece(pwesto_ng_kalaban, 0) Or block(pwesto_ng_kalaban) = 0) Then

If checked And naharangan_ba(pwesto_ng_kalaban) Then

nenah = True GoTo end_nenah

End If

End If End If

Loop

Next j Next i

'************

'* diagonal *

'************

For i = 7 To 9 Step 2 ' 7=downward , 9=upward For j = position - i To 1 Step -i 'towards left

If (block(j) = 0 Or is_black_piece(j, 0)) And

Image1(position).Tag = Image1(j).Tag Then If checked And naharangan_ba(j) Then

nenah = True

GoTo end_nenah End If

End If

If block(j) = 1 Then j = 1

End If

Next j For j = position + i To 64 Step i 'towards right

If (block(j) = 0 Or is_black_piece(j, 0)) And

Image1(position).Tag = Image1(j).Tag Then If checked And naharangan_ba(j) Then

nenah = True

GoTo end_nenah End If

End If

If block(j) = 1 Then j = 64

End If

Next j Next i

End If Case "K"

nenah = True

End Select End If 'white turn

'******** '* ITIM *

'********

If blackturn Then Select Case piece

Case "P"

If Not blocked Then If kurow = 2 Then

loops = 2

Else loops = 1

End If

For i = 1 To loops If block(position + i) = 0 Then

If checked And naharangan_ba(position + 1) Then

nenah = True

GoTo end_nenah

End If

Else i = loops

End If

Next End If

For j = 1 To -1 Step -2

If kolum + j <= 8 And kolum + j >= 1 And kurow < 8 Then pwesto_ng_kalaban = alamin_ang_pwesto(kolum + j, kurow

+ 1)

If is_white_piece(pwesto_ng_kalaban, 0) Then If checked And naharangan_ba(pwesto_ng_kalaban) Then

nenah = True

GoTo end_nenah End If

End If

End If Next j

'***************

'* passed pawn *

Page 68: PC-Based Electronic Chess Board Game

Appendix D D-19

'***************

For j = 1 To -1 Step -2 If kolum + j <= 8 And kolum + j >= 1 And kurow < 8 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum + j, kurow)

If is_white_piece(pwesto_ng_kalaban, 1) And mpassed_pawn <> 0 Then

If enpassantpiecew(mpassed_pawn) Then

If checked And naharangan_ba(pwesto_ng_kalaban) Then nenah = True

GoTo end_nenah

End If End If

End If

End If Next j

'**********

'* kabayo * '**********

Case "N"

If Not blocked Then For i = 0 To 7

Select Case i

Case 0, 5 kl = -1

Case 1, 4

kl = 1 Case 2, 3

kl = 2 Case 6, 7

kl = -2

End Select Select Case i

Case 0, 1

kr = -2 Case 2, 7

kr = -1

Case 3, 6 kr = 1

Case 4, 5

kr = 2 End Select

If (kolum + kl) <= 8 And (kolum + kl) >= 1 And (kurow +

kr) <= 8 And (kurow + kr) >= 1 Then pwesto_ng_kalaban = alamin_ang_pwesto(kolum + kl,

kurow + kr)

If is_white_piece(pwesto_ng_kalaban, 0) Or block(pwesto_ng_kalaban) = 0 Then

If checked And naharangan_ba(pwesto_ng_kalaban) Then

nenah = True

GoTo end_nenah

End If

End If End If

Next i

End If 'not blocked '********

'* tore *

'******** Case "R"

If Not blocked Then

For i = 0 To 1 '0=horizontal, 1=vertical hakbang = 1

For j = 1 To 8 Step 7 '1=decreasing, 8=increasing

hakbang = hakbang * -1 kl = kolum

kr = kurow

If i = 0 Then mlimit = kl

Else

mlimit = kr

End If

pwesto_ng_kalaban = alamin_ang_pwesto(kl, kr) Do Until mlimit = j + hakbang Or block(pwesto_ng_kalaban)

= 1

pwesto_ng_kalaban = alamin_ang_pwesto(kl, kr) If i = 0 Then

kl = kl + hakbang

mlimit = kl Else

kr = kr + hakbang

mlimit = kr End If

If position <> pwesto_ng_kalaban Then

If (is_white_piece(pwesto_ng_kalaban, 0) Or block(pwesto_ng_kalaban) = 0) Then

If checked And naharangan_ba(pwesto_ng_kalaban) Then

nenah = True GoTo end_nenah

End If

End If End If

Loop

Next j Next i

End If

'********** '* bishop *

'********** Case "B"

If Not blocked Then

'************ '* diagonal *

'************

For i = 7 To 9 Step 2 ' 7=downward , 9=upward For j = position - i To 1 Step -i 'towards left

If (block(j) = 0 Or is_white_piece(j, 0)) And

Image1(position).Tag = Image1(j).Tag Then If checked And naharangan_ba(j) Then

nenah = True

GoTo end_nenah End If

End If

If block(j) = 1 Then j = 1

End If

Next j For j = position + i To 64 Step i 'towards right

If (block(j) = 0 Or is_white_piece(j, 0)) And

Image1(position).Tag = Image1(j).Tag Then

If checked And naharangan_ba(j) Then

nenah = True

GoTo end_nenah End If

End If

If block(j) = 1 Then j = 64

End If

Next j Next i

End If

'********* '* reyna *

'*********

Case "Q" If Not blocked Then

For i = 0 To 1 '0=horizontal, 1=vertical

hakbang = 1 For j = 1 To 8 Step 7 '1=decreasing, 8=increasing

hakbang = hakbang * -1

kl = kolum

Page 69: PC-Based Electronic Chess Board Game

Appendix D D-20

kr = kurow

If i = 0 Then mlimit = kl

Else

mlimit = kr End If

pwesto_ng_kalaban = alamin_ang_pwesto(kl, kr)

Do Until mlimit = j + hakbang Or block(pwesto_ng_kalaban) = 1

pwesto_ng_kalaban = alamin_ang_pwesto(kl, kr)

If i = 0 Then kl = kl + hakbang

mlimit = kl

Else kr = kr + hakbang

mlimit = kr

End If If position <> pwesto_ng_kalaban Then

If (is_white_piece(pwesto_ng_kalaban, 0) Or

block(pwesto_ng_kalaban) = 0) Then If checked And naharangan_ba(pwesto_ng_kalaban) Then

nenah = True

GoTo end_nenah End If

End If

End If Loop

Next j Next i

'************

'* diagonal * '************

For i = 7 To 9 Step 2 ' 7=downward , 9=upward

For j = position - i To 1 Step -i 'towards left If (block(j) = 0 Or is_white_piece(j, 0)) And

Image1(position).Tag = Image1(j).Tag Then

If checked And naharangan_ba(j) Then nenah = True

GoTo end_nenah

End If End If

If block(j) = 1 Then

j = 1 End If

Next j

For j = position + i To 64 Step i 'towards right If (block(j) = 0 Or is_white_piece(j, 0)) And

Image1(position).Tag = Image1(j).Tag Then

If checked And naharangan_ba(j) Then

nenah = True

GoTo end_nenah

End If End If

If block(j) = 1 Then

j = 64 End If

Next j

Next i End If

Case "K"

nenah = True End Select

End If 'black turn

end_nenah: End Function

Private Function reset_changed_tiles() Dim tongue As Integer

For i = 1 To changed_tiles_count

tongue = changed_tiles(i)

changed_tiles(i) = 0

If tongue <> 0 Then If Image1(tongue).Tag = "white" Then

Image1(tongue).Picture = LoadPicture(App.Path &

"/images/white.jpg") End If

If Image1(tongue).Tag = "black" Then

Image1(tongue).Picture = LoadPicture(App.Path & "/images/black.jpg")

End If

led_array(tongue) = 0 End If

Next

changed_tiles_count = 0 End Function

Private Function run_command()

Dim strTemp1 As String If move_count >= 0 And run_cnt <= move_count Then

For i = 1 To 16

For j = 1 To 64 strTemp1 = Str(Image1(j).Top) & Str(Image1(j).Left)

If white_pos(i, run_cnt) = strTemp1 Then

Image6(i).Top = Image1(j).Top Image6(i).Left = Image1(j).Left

End If

If black_pos(i, run_cnt) = strTemp1 Then Image7(i).Top = Image1(j).Top

Image7(i).Left = Image1(j).Left End If

Next j

Next i End If

run_cnt = run_cnt + 1

End Function

'************************

'* magre-return ng true * '* kapag may banta ng *

'* check sa lalapagan *

'************************ Private Function square_on_threat(pos As Integer) As

Boolean

Dim pos_c As Integer, pos_r As Integer, squares As Integer Dim kl As Integer, kr As Integer, j As Integer, k As Integer

Dim mlimit As Integer, hakbang As Integer

square_on_threat = False pos_c = what_column(pos)

pos_r = what_row(pos)

If whiteturn Then

For j = 1 To -1 Step -2 ' 1 right, -1 left

If pos_c + j <= 8 And pos_c + j >= 1 And pos_r > 1 Then squares = alamin_ang_pwesto(pos_c + j, pos_r - 1)

If is_black_piece(squares, 1) Then

square_on_threat = True j = -1

End If

End If Next j

'************ '* diagonal *

'************

For i = 7 To 9 Step 2 ' 7=downward , 9=upward For j = pos - i To 1 Step -i 'towards left

If Image1(pos).Tag = Image1(j).Tag Then

If block(j) = 1 Then If is_black_piece(j, 0) Then

If (Image7(black_piece).Tag = "B" Or

Image7(black_piece).Tag = "Q") Then

Page 70: PC-Based Electronic Chess Board Game

Appendix D D-21

square_on_threat = True

GoTo end_SOT End If

End If

j = 1 End If

End If

Next j For j = pos + i To 64 Step i 'towards right

If Image1(pos).Tag = Image1(j).Tag Then

If block(j) = 1 Then If is_black_piece(j, 0) Then

If (Image7(black_piece).Tag = "B" Or

Image7(black_piece).Tag = "Q") Then square_on_threat = True

GoTo end_SOT

End If End If

j = 64

End If End If

Next j

Next i

For i = 0 To 1 '0=horizontal, 1=vertical

hakbang = 1 For j = 1 To 8 Step 7 '1=decreasing, 8=increasing

hakbang = hakbang * -1 kl = pos_c

kr = pos_r

If i = 0 Then mlimit = kl

Else

mlimit = kr End If

If mlimit <> j Then

For k = mlimit + hakbang To j Step hakbang If i = 0 Then

squares = alamin_ang_pwesto(k, kr)

Else squares = alamin_ang_pwesto(kl, k)

End If

If block(squares) = 1 Then If is_black_piece(squares, 0) Then

If (Image7(black_piece).Tag = "Q" Or

Image7(black_piece).Tag = "R") Then square_on_threat = True

GoTo end_SOT

End If

End If

k = j

End If Next k

End If

Next j Next i

i = 0 Do Until i = 7 Or square_on_threat

Select Case i

Case 0, 5 kl = -1

Case 1, 4

kl = 1 Case 2, 3

kl = 2

Case 6, 7 kl = -2

End Select

Select Case i

Case 0, 1

kr = -2 Case 2, 7

kr = -1

Case 3, 6 kr = 1

Case 4, 5

kr = 2 End Select

If (pos_c + kl) <= 8 And (pos_c + kl) >= 1 And (pos_r + kr)

<= 8 And (pos_r + kr) >= 1 Then squares = alamin_ang_pwesto(pos_c + kl, pos_r + kr)

If is_black_piece(squares, 0) Then

If black_piece > 0 Then If Image7(black_piece).Tag = "N" Then

square_on_threat = True

End If End If

End If

End If i = i + 1

Loop

End If 'whiteturn

If blackturn Then

For j = 1 To -1 Step -2 ' 1 right, -1 left If pos_c + j <= 8 And pos_c + j >= 1 And pos_r < 8 Then

squares = alamin_ang_pwesto(pos_c + j, pos_r + 1) If is_white_piece(squares, 1) Then

square_on_threat = True

End If End If

Next j

'************ '* diagonal *

'************

For i = 7 To 9 Step 2 ' 7=downward , 9=upward For j = pos - i To 1 Step -i 'towards left

If Image1(pos).Tag = Image1(j).Tag Then

If block(j) = 1 Then If is_white_piece(j, 0) Then

If (Image6(white_piece).Tag = "B" Or

Image6(white_piece).Tag = "Q") Then square_on_threat = True

GoTo end_SOT

End If End If

j = 1

End If

End If

Next j

For j = pos + i To 64 Step i 'towards right If Image1(pos).Tag = Image1(j).Tag Then

If block(j) = 1 Then

If is_white_piece(j, 0) Then If (Image6(white_piece).Tag = "B" Or

Image6(white_piece).Tag = "Q") Then

square_on_threat = True GoTo end_SOT

End If

End If j = 64

End If

End If Next j

Next i

For i = 0 To 1 '0=horizontal, 1=vertical

hakbang = 1

For j = 1 To 8 Step 7 '1=decreasing, 8=increasing

Page 71: PC-Based Electronic Chess Board Game

Appendix D D-22

hakbang = hakbang * -1

kl = pos_c kr = pos_r

If i = 0 Then

mlimit = kl Else

mlimit = kr

End If If mlimit <> j Then

For k = mlimit + hakbang To j Step hakbang

If i = 0 Then squares = alamin_ang_pwesto(k, kr)

Else

squares = alamin_ang_pwesto(kl, k) End If

If block(squares) = 1 Then

If is_white_piece(squares, 0) Then If (Image6(white_piece).Tag = "Q" Or

Image6(white_piece).Tag = "R") Then

square_on_threat = True GoTo end_SOT

End If

End If k = j

End If

Next k End If

Next j Next i

i = 0 Do Until i = 7 Or square_on_threat

Select Case i

Case 0, 5 kl = -1

Case 1, 4

kl = 1 Case 2, 3

kl = 2

Case 6, 7 kl = -2

End Select

Select Case i Case 0, 1

kr = -2

Case 2, 7 kr = -1

Case 3, 6

kr = 1

Case 4, 5

kr = 2

End Select If (pos_c + kl) <= 8 And (pos_c + kl) >= 1 And (pos_r + kr)

<= 8 And (pos_r + kr) >= 1 Then

squares = alamin_ang_pwesto(pos_c + kl, pos_r + kr) If is_white_piece(squares, 0) Then

If white_piece > 0 Then

If Image6(white_piece).Tag = "N" Then square_on_threat = True

End If

End If End If

End If

i = i + 1 Loop

End If 'blackturn

end_SOT: End Function

Private Function stalemate_ba() As Boolean

Dim kolum As Integer, kurow As Integer,

pwesto_ng_kalaban As Integer Dim i As Integer, j As Integer, hakbang As Integer, leche As

String

Dim kl As Integer, kr As Integer, local_pos As Integer stalemate_ba = True

For local_pos = 1 To 64

kolum = what_column(local_pos) kurow = what_row(local_pos)

'********

'* PUTI * '********

If whiteturn Then

If is_white_piece(local_pos, 0) Then leche = Image6(white_piece).Tag

Select Case leche

'******** '* pawn *

'********

Case "P" If block(local_pos - 1) = 0 Or ((Not is_white_piece(local_pos

- 1, 0)) And (Not is_black_piece(local_pos - 1, 0))) Then

stalemate_ba = False GoTo end_stalemate_ba

End If

'**************** '* may makakain *

'**************** For j = 1 To -1 Step -2

If kolum + j <= 8 And kolum + j >= 1 And kurow > 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum + j, kurow - 1)

If is_black_piece(pwesto_ng_kalaban, 0) Then

stalemate_ba = False GoTo end_stalemate_ba

End If

End If Next j

'***************

'* passed pawn * '***************

For j = 1 To -1 Step -2

If kolum + j <= 8 And kolum + j >= 1 And kurow > 1 Then pwesto_ng_kalaban = alamin_ang_pwesto(kolum + j, kurow)

If is_black_piece(pwesto_ng_kalaban, 1) And

mpassed_pawn <> 0 Then If enpassantpieceb(mpassed_pawn) Then

stalemate_ba = False

GoTo end_stalemate_ba

End If

End If

End If Next j

'**********

'* kabayo * '**********

Case "N"

For i = 0 To 7 Select Case i

Case 0, 5

kl = -1 Case 1, 4

kl = 1

Case 2, 3 kl = 2

Case 6, 7

kl = -2 End Select

Select Case i

Case 0, 1

Page 72: PC-Based Electronic Chess Board Game

Appendix D D-23

kr = -2

Case 2, 7 kr = -1

Case 3, 6

kr = 1 Case 4, 5

kr = 2

End Select If (kolum + kl) <= 8 And (kolum + kl) >= 1 And (kurow +

kr) <= 8 And (kurow + kr) >= 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum + kl, kurow + kr)

If is_black_piece(pwesto_ng_kalaban, 0) Or

(block(pwesto_ng_kalaban) = 0 Or (Not is_white_piece(pwesto_ng_kalaban, 0))) Then

stalemate_ba = False

GoTo end_stalemate_ba End If

End If

Next i '********

'* tore *

'******** Case "R"

For i = 0 To 1 '0=horizontal, 1=vertical

hakbang = 1 For j = 1 To 8 Step 7 '1=decreasing, 8=increasing

hakbang = hakbang * -1 If i = 1 Then

If kurow < 8 And kurow > 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum, kurow + hakbang)

If is_black_piece(pwesto_ng_kalaban, 0) Or

block(pwesto_ng_kalaban) = 0 Or (Not is_white_piece(pwesto_ng_kalaban, 0)) Then

stalemate_ba = False

GoTo end_stalemate_ba End If

End If

Else If kolum < 8 And kolum > 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum + hakbang,

kurow) If is_black_piece(pwesto_ng_kalaban, 0) Or

block(pwesto_ng_kalaban) = 0 Or (Not

is_white_piece(pwesto_ng_kalaban, 0)) Then stalemate_ba = False

GoTo end_stalemate_ba

End If

End If

End If

Next j Next i

'**********

'* bishop * '**********

Case "B"

'************ '* diagonal *

'************

For i = 7 To 9 Step 2 ' 7=downward , 9=upward For k = 1 To -1 Step -2 '1 towards right, -1 towards left

j = local_pos + (i * k)

If ((Not is_white_piece(j, 0)) Or block(j) = 0 Or is_black_piece(j, 0)) And Image1(local_pos).Tag =

Image1(j).Tag And j > 0 And j < 65 Then

stalemate_ba = False GoTo end_stalemate_ba

End If

Next k

Next i

'********* '* reyna *

'*********

Case "Q" For i = 0 To 1 '0=horizontal, 1=vertical

hakbang = 1

For j = 1 To 8 Step 7 '1=decreasing, 8=increasing hakbang = hakbang * -1

If i = 1 Then

If kurow < 8 And kurow > 1 Then pwesto_ng_kalaban = alamin_ang_pwesto(kolum, kurow +

hakbang)

If (Not is_white_piece(pwesto_ng_kalaban, 0)) Or block(pwesto_ng_kalaban) = 0 Or (Not

is_white_piece(pwesto_ng_kalaban, 0)) Then

stalemate_ba = False GoTo end_stalemate_ba

End If

End If Else

If kolum < 8 And kolum > 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum + hakbang, kurow)

If (Not is_white_piece(pwesto_ng_kalaban, 0)) Or

block(pwesto_ng_kalaban) = 0 Or (Not is_white_piece(pwesto_ng_kalaban, 0)) Then

stalemate_ba = False GoTo end_stalemate_ba

End If

End If End If

Next j

Next i '************

'* diagonal *

'************ For i = 7 To 9 Step 2 ' 7=downward , 9=upward

For k = 1 To -1 Step -2 '1 towards right, -1 towards left

j = local_pos + (i * k) If (block(j) = 0 Or is_black_piece(j, 0) Or (Not

is_white_piece(j, 0))) And Image1(local_pos).Tag =

Image1(j).Tag And j > 0 And j < 65 Then stalemate_ba = False

GoTo end_stalemate_ba

End If Next k

Next i

Case "K"

'*************

'* left side *

'************* If kolum <= 8 And kolum > 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum - 1, kurow)

If (block(pwesto_ng_kalaban) = 0 Or is_black_piece(pwesto_ng_kalaban, 0) Or (Not

is_white_piece(pwesto_ng_kalaban, 0))) And Not

square_on_threat(pwesto_ng_kalaban) Then stalemate_ba = False

GoTo end_stalemate_ba

End If End If

'**************

'* right side * '**************

If kolum < 8 And kolum >= 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum + 1, kurow)

If (block(pwesto_ng_kalaban) = 0 Or

is_black_piece(pwesto_ng_kalaban, 0) Or (Not

Page 73: PC-Based Electronic Chess Board Game

Appendix D D-24

is_white_piece(pwesto_ng_kalaban, 0))) And Not

square_on_threat(pwesto_ng_kalaban) Then stalemate_ba = False

GoTo end_stalemate_ba

End If End If

'*********

'* above * '*********

If kurow <= 8 And kurow > 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum, kurow - 1) If (block(pwesto_ng_kalaban) = 0 Or

is_black_piece(pwesto_ng_kalaban, 0) Or (Not

is_white_piece(pwesto_ng_kalaban, 0))) And Not square_on_threat(pwesto_ng_kalaban) Then

stalemate_ba = False

GoTo end_stalemate_ba End If

End If

'********* '* below *

'*********

If kurow < 8 And kurow >= 1 Then pwesto_ng_kalaban = alamin_ang_pwesto(kolum, kurow +

1)

If (block(pwesto_ng_kalaban) = 0 Or is_black_piece(pwesto_ng_kalaban, 0) Or (Not

is_white_piece(pwesto_ng_kalaban, 0))) And Not square_on_threat(pwesto_ng_kalaban) Then

stalemate_ba = False

GoTo end_stalemate_ba End If

End If

'************ '* top left *

'************

If kolum <= 8 And kolum > 1 And kurow <= 8 And kurow > 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum - 1, kurow

- 1) If (block(pwesto_ng_kalaban) = 0 Or

is_black_piece(pwesto_ng_kalaban, 0) Or (Not

is_white_piece(pwesto_ng_kalaban, 0))) And Not square_on_threat(pwesto_ng_kalaban) Then

stalemate_ba = False

GoTo end_stalemate_ba End If

End If

'*************

'* top right *

'*************

If kolum < 8 And kolum >= 1 And kurow <= 8 And kurow > 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum + 1, kurow

- 1) If (block(pwesto_ng_kalaban) = 0 Or

is_black_piece(pwesto_ng_kalaban, 0) Or (Not

is_white_piece(pwesto_ng_kalaban, 0))) And Not square_on_threat(pwesto_ng_kalaban) Then

stalemate_ba = False

GoTo end_stalemate_ba End If

End If

'*************** '* bottom left *

'***************

If kolum <= 8 And kolum > 1 And kurow < 8 And kurow >= 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum - 1, kurow

+ 1)

If (block(pwesto_ng_kalaban) = 0 Or

is_black_piece(pwesto_ng_kalaban, 0) Or (Not is_white_piece(pwesto_ng_kalaban, 0))) And Not

square_on_threat(pwesto_ng_kalaban) Then

stalemate_ba = False GoTo end_stalemate_ba

End If

End If '****************

'* bottom right *

'**************** If kolum < 8 And kolum >= 1 And kurow < 8 And kurow >=

1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum + 1, kurow + 1)

If (block(pwesto_ng_kalaban) = 0 Or

is_black_piece(pwesto_ng_kalaban, 0) Or (Not is_white_piece(pwesto_ng_kalaban, 0))) And Not

square_on_threat(pwesto_ng_kalaban) Then

stalemate_ba = False GoTo end_stalemate_ba

End If

End If End Select

End If 'white piece

End If 'white turn '--------------------------------------------------------------

'******** '* ITIM *

'********

If blackturn Then If is_black_piece(local_pos, 0) Then

leche = Image7(black_piece).Tag

Select Case leche Case "P"

If block(local_pos + 1) = 0 Or ((Not

is_white_piece(local_pos + 1, 0)) And (Not is_black_piece(local_pos + 1, 0))) Then

stalemate_ba = False

GoTo end_stalemate_ba End If

'****************

'* may makakain * '****************

For j = 1 To -1 Step -2

If kolum + j <= 8 And kolum + j >= 1 And kurow > 1 Then pwesto_ng_kalaban = alamin_ang_pwesto(kolum + j, kurow

+ 1)

If is_white_piece(pwesto_ng_kalaban, 0) Then

stalemate_ba = False

GoTo end_stalemate_ba

End If End If

Next j

'*************** '* passed pawn *

'***************

For j = 1 To -1 Step -2 If kolum + j <= 8 And kolum + j >= 1 And kurow > 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum + j, kurow)

If is_white_piece(pwesto_ng_kalaban, 1) And mpassed_pawn <> 0 Then

If enpassantpieceb(mpassed_pawn) Then

stalemate_ba = False GoTo end_stalemate_ba

End If

End If End If

Next j

'**********

Page 74: PC-Based Electronic Chess Board Game

Appendix D D-25

'* kabayo *

'********** Case "N"

If Not blocked Then

For i = 0 To 7 Select Case i

Case 0, 5

kl = -1 Case 1, 4

kl = 1

Case 2, 3 kl = 2

Case 6, 7

kl = -2 End Select

Select Case i

Case 0, 1 kr = -2

Case 2, 7

kr = -1 Case 3, 6

kr = 1

Case 4, 5 kr = 2

End Select

If (kolum + kl) <= 8 And (kolum + kl) >= 1 And (kurow + kr) <= 8 And (kurow + kr) >= 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum + kl, kurow + kr)

If is_white_piece(pwesto_ng_kalaban, 0) Or

block(pwesto_ng_kalaban) = 0 Or (Not is_black_piece(pwesto_ng_kalaban, 0)) Then

stalemate_ba = False

GoTo end_stalemate_ba End If

End If

Next i End If 'not blocked

'********

'* tore * '********

Case "R"

For i = 0 To 1 '0=horizontal, 1=vertical hakbang = 1

For j = 1 To 8 Step 7 '1=decreasing, 8=increasing

hakbang = hakbang * -1 If i = 1 Then

If kurow < 8 And kurow > 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum, kurow +

hakbang)

If is_white_piece(pwesto_ng_kalaban, 0) Or

block(pwesto_ng_kalaban) = 0 Or (Not is_black_piece(pwesto_ng_kalaban, 0)) Then

stalemate_ba = False

GoTo end_stalemate_ba End If

End If

Else If kolum < 8 And kolum > 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum + hakbang,

kurow) If is_white_piece(pwesto_ng_kalaban, 0) Or

block(pwesto_ng_kalaban) = 0 Or (Not

is_black_piece(pwesto_ng_kalaban, 0)) Then stalemate_ba = False

GoTo end_stalemate_ba

End If End If

End If

Next j

Next i

'********** '* bishop *

'**********

Case "B" '************

'* diagonal *

'************ For i = 7 To 9 Step 2 ' 7=downward , 9=upward

For k = 1 To -1 Step -2 '1 towards right, -1 towards left

j = local_pos + (i * k) If (block(j) = 0 Or is_white_piece(j, 0) Or (Not

is_black_piece(j, 0))) And Image1(local_pos).Tag =

Image1(j).Tag And j > 0 And j < 65 Then stalemate_ba = False

GoTo end_stalemate_ba

End If Next k

Next i

'********* '* reyna *

'*********

Case "Q" For i = 0 To 1 '0=horizontal, 1=vertical

hakbang = 1

For j = 1 To 8 Step 7 '1=decreasing, 8=increasing hakbang = hakbang * -1

If i = 1 Then If kurow < 8 And kurow > 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum, kurow +

hakbang) If is_white_piece(pwesto_ng_kalaban, 0) Or

block(pwesto_ng_kalaban) = 0 Or (Not

is_black_piece(pwesto_ng_kalaban, 0)) Then stalemate_ba = False

GoTo end_stalemate_ba

End If End If

Else

If kolum < 8 And kolum > 1 Then pwesto_ng_kalaban = alamin_ang_pwesto(kolum + hakbang,

kurow)

If is_white_piece(pwesto_ng_kalaban, 0) Or block(pwesto_ng_kalaban) = 0 Or (Not

is_black_piece(pwesto_ng_kalaban, 0)) Then

stalemate_ba = False GoTo end_stalemate_ba

End If

End If

End If

Next j

Next i '************

'* diagonal *

'************ For i = 7 To 9 Step 2 ' 7=downward , 9=upward

For k = 1 To -1 Step -2 '1 towards right, -1 towards left

j = local_pos + (i * k) If (block(j) = 0 Or is_white_piece(j, 0) Or (Not

is_black_piece(j, 0))) And Image1(local_pos).Tag =

Image1(j).Tag And j > 0 And j < 65 Then stalemate_ba = False

GoTo end_stalemate_ba

End If Next k

Next i

Case "K" '*************

'* left side *

'*************

Page 75: PC-Based Electronic Chess Board Game

Appendix D D-26

If kolum <= 8 And kolum > 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum - 1, kurow) If (block(pwesto_ng_kalaban) = 0 Or

is_white_piece(pwesto_ng_kalaban, 0) Or (Not

is_black_piece(pwesto_ng_kalaban, 0))) And Not square_on_threat(pwesto_ng_kalaban) Then

stalemate_ba = False

GoTo end_stalemate_ba End If

End If

'************** '* right side *

'**************

If kolum < 8 And kolum >= 1 Then pwesto_ng_kalaban = alamin_ang_pwesto(kolum + 1,

kurow)

If (block(pwesto_ng_kalaban) = 0 Or is_white_piece(pwesto_ng_kalaban, 0) Or (Not

is_black_piece(pwesto_ng_kalaban, 0))) And Not

square_on_threat(pwesto_ng_kalaban) Then stalemate_ba = False

GoTo end_stalemate_ba

End If End If

'*********

'* above * '*********

If kurow <= 8 And kurow > 1 Then pwesto_ng_kalaban = alamin_ang_pwesto(kolum, kurow - 1)

If (block(pwesto_ng_kalaban) = 0 Or

is_white_piece(pwesto_ng_kalaban, 0) Or (Not is_black_piece(pwesto_ng_kalaban, 0))) And Not

square_on_threat(pwesto_ng_kalaban) Then

stalemate_ba = False GoTo end_stalemate_ba

End If

End If '*********

'* below *

'********* If kurow < 8 And kurow >= 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum, kurow +

1) If (block(pwesto_ng_kalaban) = 0 Or

is_white_piece(pwesto_ng_kalaban, 0) Or (Not

is_black_piece(pwesto_ng_kalaban, 0))) And Not square_on_threat(pwesto_ng_kalaban) Then

stalemate_ba = False

GoTo end_stalemate_ba

End If

End If

'************ '* top left *

'************

If kolum <= 8 And kolum > 1 And kurow <= 8 And kurow > 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum - 1, kurow

- 1) If (block(pwesto_ng_kalaban) = 0 Or

is_white_piece(pwesto_ng_kalaban, 0) Or (Not

is_black_piece(pwesto_ng_kalaban, 0))) And Not square_on_threat(pwesto_ng_kalaban) Then

stalemate_ba = False

GoTo end_stalemate_ba End If

End If

'************* '* top right *

'*************

If kolum < 8 And kolum >= 1 And kurow <= 8 And kurow >

1 Then pwesto_ng_kalaban = alamin_ang_pwesto(kolum + 1, kurow

- 1)

If (block(pwesto_ng_kalaban) = 0 Or is_white_piece(pwesto_ng_kalaban, 0) Or (Not

is_black_piece(pwesto_ng_kalaban, 0))) And Not

square_on_threat(pwesto_ng_kalaban) Then stalemate_ba = False

GoTo end_stalemate_ba

End If End If

'***************

'* bottom left * '***************

If kolum <= 8 And kolum > 1 And kurow < 8 And kurow >=

1 Then pwesto_ng_kalaban = alamin_ang_pwesto(kolum - 1, kurow

+ 1)

If (block(pwesto_ng_kalaban) = 0 Or is_white_piece(pwesto_ng_kalaban, 0) Or (Not

is_black_piece(pwesto_ng_kalaban, 0))) And Not

square_on_threat(pwesto_ng_kalaban) Then stalemate_ba = False

GoTo end_stalemate_ba

End If End If

'**************** '* bottom right *

'****************

If kolum < 8 And kolum >= 1 And kurow < 8 And kurow >= 1 Then

pwesto_ng_kalaban = alamin_ang_pwesto(kolum + 1, kurow

+ 1) If (block(pwesto_ng_kalaban) = 0 Or

is_white_piece(pwesto_ng_kalaban, 0) Or (Not

is_black_piece(pwesto_ng_kalaban, 0))) And Not square_on_threat(pwesto_ng_kalaban) Then

stalemate_ba = False

GoTo end_stalemate_ba End If

End If

End Select End If

End If 'black turn

Next local_pos end_stalemate_ba:

draw = stalemate_ba

End Function

Private Function step_back()

Dim strTemp1 As String If move_count >= 0 And run_cnt > 0 Then

run_cnt = run_cnt - 1

For i = 1 To 16 For j = 1 To 64

strTemp1 = Str(Image1(j).Top) & Str(Image1(j).Left)

If white_pos(i, run_cnt) = strTemp1 Then Image6(i).Top = Image1(j).Top

Image6(i).Left = Image1(j).Left

End If If black_pos(i, run_cnt) = strTemp1 Then

Image7(i).Top = Image1(j).Top

Image7(i).Left = Image1(j).Left End If

Next j

Next i End If

End Function

Page 76: PC-Based Electronic Chess Board Game

Appendix D D-27

Private Function takbo(mensahe As String)

lblmessage.Caption = mensahe lblmessage.Top = Me.Height / 3

If lblmessage.Left > (Me.Width / 100) Then

lblmessage.Left = lblmessage.Left - (Me.Width / 150) End If

End Function

Private Function what_column(pwesto As Integer) As Integer

For i = 1 To 8

If pwesto < (1 + (i * 8)) Then what_column = i

i = 8

End If Next

End Function

Private Function what_row(pwesto As Integer) As Integer

For i = 1 To 8

If pwesto = i Or pwesto = (i + 8) Or pwesto = (i + (8 * 2)) Or pwesto = (i + (8 * 3)) Or pwesto = (i + (8 * 4)) Or pwesto =

(i + (8 * 5)) Or pwesto = (i + (8 * 6)) Or pwesto = (i + (8 *

7)) Then what_row = i

i = 8

End If Next

End Function

Private Function append_list()

Dim str_players_moves As String, kukuro As Integer, ddd As String

If Not hula Then

hula = Not hula If piece = "P" Then

ddd = ""

Else ddd = piece

End If

If checked Then str_players_moves = ddd & moveto & "+"

lst_moves.AddItem str_players_moves

Else If there_is_pawn_promote Then

str_players_moves = ddd & moveto & " " & piecepromoted

lst_moves.AddItem str_players_moves Else

If Not castling Then

str_players_moves = ddd & moveto

lst_moves.AddItem str_players_moves

Else

If rook = 16 Then str_players_moves = "O-O"

lst_moves.AddItem str_players_moves

Else str_players_moves = "O-O-O"

lst_moves.AddItem str_players_moves

End If End If

End If

End If there_is_pawn_promote = False

Else

hula = Not hula If piece = "P" Then

ddd = ""

Else ddd = piece

End If

If checked Then

str_players_moves = ddd & moveto & "+"

lst_moves.List(bturn2) = lst_moves.List(bturn2) & " " & str_players_moves

Else

If there_is_pawn_promote Then str_players_moves = ddd & moveto & " " & piecepromoted

lst_moves.List(bturn2) = lst_moves.List(bturn2) & " " &

str_players_moves Else

If Not castling Then

str_players_moves = ddd & moveto lst_moves.List(bturn2) = lst_moves.List(bturn2) & " " &

str_players_moves

Else If rook = 16 Then

str_players_moves = "O-O"

lst_moves.List(bturn2) = lst_moves.List(bturn2) & " " & str_players_moves

Else

str_players_moves = "O-O-O" lst_moves.List(bturn2) = lst_moves.List(bturn2) & " " &

str_players_moves

End If End If

End If

End If bturn2 = bturn2 + 1

there_is_pawn_promote = False End If

kukuro = lst_moves.ListCount - 1

lst_moves.ListIndex = kukuro End Function

Private Function obstruction(ind As Integer) As Boolean stops = False

obstruction = False

If picked Then '***********************

'* RIGHTSIDE

If ind = 56 Then '*******************

'* HORSE

For j = 38 To 62 Step 8 For i = 1 To 16

If Image1(j).Top = Image7(i).Top And Image1(j).Left =

Image7(i).Left Then If Image7(i).Tag = "N" Then

obstruction = True

End If

End If

Next i

Next j '*******************

'* ROOK & QUEEN

For j = 48 To 56 Step 8 For k = j - 1 To 1 Step -1

For i = 1 To 16

If Not stops Then If Image1(k).Left = Image1(j).Left Then

If Image1(k).Left = Image6(i).Left And Image1(k).Top =

Image6(i).Top Then stops = True

Else

If Image1(k).Left = Image7(i).Left And Image1(k).Top = Image7(i).Top Then

If Image7(i).Tag = "R" Or Image7(i).Tag = "Q" Then

obstruction = True End If

End If

End If

Page 77: PC-Based Electronic Chess Board Game

Appendix D D-28

End If

End If Next i

Next k

stops = False Next j

'***********************

'* BISHOP & QUEEN & PAWN For j = 48 To 56 Step 8

For k = j - 9 To 1 Step -9

For i = 1 To 16 If Not stops Then

If Image1(j).Tag = Image1(k).Tag Then

If Image6(i).Top = Image1(k).Top And Image6(i).Left = Image1(k).Left Then

stops = True

Else If Image7(i).Top = Image1(k).Top And Image7(i).Left =

Image1(k).Left Then

If k = j - 9 And Image7(i).Tag = "P" Then stops = True

obstruction = True

Else If Image7(i).Tag = "Q" Or Image7(i).Tag = "B" Then

obstruction = True

End If End If

End If End If

End If

End If Next i

Next k

stops = False For k = j + 7 To 64 Step 7

For i = 1 To 16

If Not stops Then If Image1(j).Tag = Image1(k).Tag Then

If Image6(i).Top = Image1(k).Top And Image6(i).Left =

Image1(k).Left Then stops = True

Else

If Image7(i).Top = Image1(k).Top And Image7(i).Left = Image1(k).Left Then

If k = j + 7 And Image7(i).Tag = "P" Then

obstruction = True stops = True

Else

If Image7(i).Tag = "Q" Or Image7(i).Tag = "B" Then

obstruction = True

End If

End If End If

End If

End If End If

Next i

Next k stops = False

Next j

End If '***********************

'* LEFTSIDE

If ind = 24 Then '*******************

'* HORSE

For j = 14 To 38 Step 8 For i = 1 To 16

If Image1(j).Top = Image7(i).Top And Image1(j).Left =

Image7(i).Left Then

If Image7(i).Tag = "N" Then

obstruction = True End If

End If

Next i Next j

'*******************

'* ROOK & QUEEN For j = 24 To 32 Step 8

For k = j - 1 To 1 Step -1

For i = 1 To 16 If Not stops Then

If Image1(k).Left = Image1(j).Left Then

If Image1(k).Left = Image6(i).Left And Image1(k).Top = Image6(i).Top Then

stops = True

Else If Image1(k).Left = Image7(i).Left And Image1(k).Top =

Image7(i).Top Then

If Image7(i).Tag = "R" Or Image7(i).Tag = "Q" Then obstruction = True

End If

End If End If

End If

End If Next i

Next k stops = False

Next j

'*********************** '* BISHOP & QUEEN & PAWN

For j = 24 To 32 Step 8

For k = j - 9 To 1 Step -9 For i = 1 To 16

If Not stops Then

If Image1(j).Tag = Image1(k).Tag Then If Image6(i).Top = Image1(k).Top And Image6(i).Left =

Image1(k).Left Then

stops = True Else

If Image7(i).Top = Image1(k).Top And Image7(i).Left =

Image1(k).Left Then If k = j - 9 And Image7(i).Tag = "P" Then

obstruction = True

stops = True Else

If Image7(i).Tag = "Q" Or Image7(i).Tag = "B" Then

obstruction = True

End If

End If

End If End If

End If

End If Next i

Next k

stops = False For k = j + 7 To 64 Step 7

For i = 1 To 16

If Not stops Then If Image1(j).Tag = Image1(k).Tag Then

If Image6(i).Top = Image1(k).Top And Image6(i).Left =

Image1(k).Left Then stops = True

Else

If Image7(i).Top = Image1(k).Top And Image7(i).Left = Image1(k).Left Then

If k = j + 7 And Image7(i).Tag = "P" Then

obstruction = True

Page 78: PC-Based Electronic Chess Board Game

Appendix D D-29

stops = True

Else If Image7(i).Tag = "Q" Or Image7(i).Tag = "B" Then

obstruction = True

End If End If

End If

End If End If

End If

Next i Next k

stops = False

Next j End If

End If

If bpicked Then

'***********************

'* RIGHTSIDE If ind = 49 Then

'*******************

'* HORSE For j = 35 To 59 Step 8

For i = 1 To 16

If Image1(j).Top = Image6(i).Top And Image1(j).Left = Image6(i).Left Then

If Image6(i).Tag = "N" Then obstruction = True

End If

End If Next i

Next j

'******************* '* ROOK & QUEEN

For j = 41 To 49 Step 8

For k = j + 1 To 64 For i = 1 To 16

If Not stops Then

If Image1(k).Left = Image1(j).Left Then If Image1(k).Left = Image7(i).Left And Image1(k).Top =

Image7(i).Top Then

stops = True Else

If Image1(k).Left = Image6(i).Left And Image1(k).Top =

Image6(i).Top Then If Image6(i).Tag = "R" Or Image6(i).Tag = "Q" Then

obstruction = True

End If

End If

End If

End If End If

Next i

Next k stops = False

Next j

'*********************** '* BISHOP & QUEEN & PAWN

For j = 41 To 49 Step 8

For k = j - 7 To 1 Step -7 For i = 1 To 16

If Not stops Then

If Image1(j).Tag = Image1(k).Tag Then If Image7(i).Top = Image1(k).Top And Image7(i).Left =

Image1(k).Left Then

stops = True Else

If Image6(i).Top = Image1(k).Top And Image6(i).Left =

Image1(k).Left Then

If k = j - 7 And Image6(i).Tag = "P" Then

obstruction = True stops = True

Else

If Image6(i).Tag = "Q" Or Image6(i).Tag = "B" Then obstruction = True

End If

End If End If

End If

End If End If

Next i

Next k stops = False

For k = j + 9 To 64 Step 9

For i = 1 To 16 If Not stops Then

If Image1(j).Tag = Image1(k).Tag Then

If Image7(i).Top = Image1(k).Top And Image7(i).Left = Image1(k).Left Then

stops = True

Else If Image6(i).Top = Image1(k).Top And Image6(i).Left =

Image1(k).Left Then

If k = j + 9 And Image6(i).Tag = "P" Then obstruction = True

stops = True Else

If Image6(i).Tag = "Q" Or Image6(i).Tag = "B" Then

obstruction = True End If

End If

End If End If

End If

End If Next i

Next k

stops = False Next j

End If

'*********************** '* LEFTSIDE

If ind = 17 Then

'******************* '* HORSE

For j = 11 To 35 Step 8

For i = 1 To 16

If Image1(j).Top = Image6(i).Top And Image1(j).Left =

Image6(i).Left Then

If Image6(i).Tag = "N" Then obstruction = True

End If

End If Next i

Next j

'******************* '* ROOK & QUEEN

For j = 17 To 25 Step 8

For k = j + 1 To 64 For i = 1 To 16

If Not stops Then

If Image1(k).Left = Image1(j).Left Then If Image1(k).Left = Image7(i).Left And Image1(k).Top =

Image7(i).Top Then

stops = True Else

If Image1(k).Left = Image6(i).Left And Image1(k).Top =

Image6(i).Top Then

Page 79: PC-Based Electronic Chess Board Game

Appendix D D-30

If Image6(i).Tag = "R" Or Image6(i).Tag = "Q" Then

obstruction = True End If

End If

End If End If

End If

Next i Next k

stops = False

Next j '***********************

'* BISHOP & QUEEN & PAWN

For j = 17 To 25 Step 8 For k = j - 7 To 1 Step -7

For i = 1 To 16

If Not stops Then If Image1(j).Tag = Image1(k).Tag Then

If Image7(i).Top = Image1(k).Top And Image7(i).Left =

Image1(k).Left Then stops = True

Else

If Image6(i).Top = Image1(k).Top And Image6(i).Left = Image1(k).Left Then

If k = j - 7 And Image6(i).Tag = "P" Then

obstruction = True stops = True

Else If Image6(i).Tag = "Q" Or Image6(i).Tag = "B" Then

obstruction = True

End If End If

End If

End If End If

End If

Next i Next k

stops = False

For k = j + 9 To 64 Step 9 For i = 1 To 16

If Not stops Then

If Image1(j).Tag = Image1(k).Tag Then If Image7(i).Top = Image1(k).Top And Image7(i).Left =

Image1(k).Left Then

stops = True Else

If Image6(i).Top = Image1(k).Top And Image6(i).Left =

Image1(k).Left Then

If k = j + 9 And Image6(i).Tag = "P" Then

obstruction = True

stops = True Else

If Image6(i).Tag = "Q" Or Image6(i).Tag = "B" Then

obstruction = True End If

End If

End If End If

End If

End If Next i

Next k

stops = False Next j

End If

End If End Function

Private Function Castable(ind As Integer) As Boolean

Castable = False

If picked Then If ind = 56 And Not kingwhitemoved And Not

rightrookwhitemoved Then

Castable = True rook = 16

rookdes = 48

End If If ind = 24 And Not kingwhitemoved And Not

leftrookwhitemoved Then

Castable = True rook = 9

rookdes = 32

End If End If

If bpicked Then If ind = 49 And Not kingblackmoved And Not

rightrookblackmoved Then

Castable = True rook = 16

rookdes = 41

End If If ind = 17 And Not kingblackmoved And Not

leftrookblackmoved Then

Castable = True rook = 9

rookdes = 25 End If

End If

End Function

Private Function endbottom() As Boolean

endbottom = False For i = 8 To 64 Step 8

If Image1(position).Top = Image1(i).Top And

Image1(position).Left = Image1(i).Left Then endbottom = True

End If

Next i End Function

Private Function OnOpenCheckTiles(square_number As Integer) As Boolean

OnOpenCheckTiles = False

For i = 1 To OpenCheckTilesCount If square_number = OpenCheckTiles(i) Then

OnOpenCheckTiles = True

i = OpenCheckTilesCount

End If

Next i

End Function Private Function opencheck() As Boolean

Dim blo As Boolean, OPCrow As Integer, OPCcolumn As

Integer, pctr As Integer, meron As Boolean Dim andyan As Boolean, kl As Integer, kr As Integer, k As

Integer, squares As Integer, hakbang As Integer

Dim mlimit As Integer, j As Integer opencheck = False

blo = False

OpenCheckTilesCount = 0 OPCrow = what_row(position)

OPCcolumn = what_column(position)

If whiteturn Then For i = 1 To 64

If Image6(13).Top = Image1(i).Top And Image6(13).Left =

Image1(i).Left Then kingpos = i

i = 64

End If

Page 80: PC-Based Electronic Chess Board Game

Appendix D D-31

Next i

If piece <> "K" Then

Select Case piece

Case "N" For i = 0 To 1 '0=horizontal, 1=vertical

hakbang = 1

For j = 1 To 8 Step 7 '1=decreasing, 8=increasing hakbang = hakbang * -1

kl = what_column(kingpos)

kr = what_row(kingpos) If i = 0 Then

mlimit = kl

Else mlimit = kr

End If

If mlimit <> j Then For k = mlimit + hakbang To j Step hakbang

If i = 0 Then

squares = alamin_ang_pwesto(k, kr) Else

squares = alamin_ang_pwesto(kl, k)

End If If position = squares Then

andyan = True

End If

If block(squares) = 1 Then If is_black_piece(squares, 0) Then

If (Image7(black_piece).Tag = "Q" Or

Image7(black_piece).Tag = "R") Then meron = True

k = j

End If End If

pctr = pctr + 1

End If Next k

If pctr = 1 And meron And andyan Then

opencheck = True GoTo exit_open_check

Else

OpenCheckTilesCount = 0 pctr = 0

meron = False

andyan = False End If

End If

Next j

Next i

'****** pahalang ******

For i = 7 To 9 Step 2 ' 7=downward , 9=upward For j = kingpos - i To 1 Step -i 'towards left

If Image1(kingpos).Tag = Image1(j).Tag Then

If position = j Then andyan = True

End If

If block(j) = 1 Then If is_black_piece(j, 0) Then

If (Image7(black_piece).Tag = "B" Or

Image7(black_piece).Tag = "Q") Then meron = True

j = 1

End If End If

pctr = pctr + 1

End If End If

Next j

If pctr = 1 And meron And andyan Then

opencheck = True

GoTo exit_open_check Else

OpenCheckTilesCount = 0

pctr = 0 meron = False

andyan = False

End If For j = kingpos + i To 64 Step i 'towards right

If Image1(kingpos).Tag = Image1(j).Tag Then

If position = j Then andyan = True

End If

If block(j) = 1 Then If is_black_piece(j, 0) Then

If (Image7(black_piece).Tag = "B" Or

Image7(black_piece).Tag = "Q") Then meron = True

j = 64

End If End If

pctr = pctr + 1

End If End If

Next j

If pctr = 1 And meron And andyan Then opencheck = True

GoTo exit_open_check Else

OpenCheckTilesCount = 0

pctr = 0 meron = False

andyan = False

End If Next i

'* *

'* BISHOP * '* *

Case "B"

For i = 0 To 1 '0=horizontal, 1=vertical hakbang = 1

For j = 1 To 8 Step 7 '1=decreasing, 8=increasing

hakbang = hakbang * -1 kl = what_column(kingpos)

kr = what_row(kingpos)

If i = 0 Then mlimit = kl

Else

mlimit = kr

End If

If mlimit <> j Then

For k = mlimit + hakbang To j Step hakbang If i = 0 Then

squares = alamin_ang_pwesto(k, kr)

Else squares = alamin_ang_pwesto(kl, k)

End If

If position = squares Then andyan = True

End If If block(squares) = 1 Then

If is_black_piece(squares, 0) Then

If (Image7(black_piece).Tag = "Q" Or Image7(black_piece).Tag = "R") Then

meron = True

k = j End If

End If

pctr = pctr + 1

Page 81: PC-Based Electronic Chess Board Game

Appendix D D-32

End If

Next k If pctr = 1 And meron And andyan Then

opencheck = True

GoTo exit_open_check Else

OpenCheckTilesCount = 0

pctr = 0 meron = False

andyan = False

End If End If

Next j

Next i '>>>>PAGHAHANAP NG PWEDENG LAPAGAN PARA

DI OPEN CHECK<<<<

For i = 7 To 9 Step 2 ' 7=downward , 9=upward For j = kingpos - i To 1 Step -i 'towards left

If Image1(kingpos).Tag = Image1(j).Tag Then

If position = j Then andyan = True

Else

OpenCheckTilesCount = OpenCheckTilesCount + 1 OpenCheckTiles(OpenCheckTilesCount) = j

End If

If block(j) = 1 Then If is_black_piece(j, 0) Then

If (Image7(black_piece).Tag = "B" Or Image7(black_piece).Tag = "Q") Then

meron = True

j = 1 End If

End If

pctr = pctr + 1 End If

End If

Next j If pctr = 1 And meron And andyan Then

GoTo exit_open_check

Else OpenCheckTilesCount = 0

pctr = 0

meron = False andyan = False

End If

For j = kingpos + i To 64 Step i 'towards right If Image1(kingpos).Tag = Image1(j).Tag Then

If position = j Then

andyan = True

Else

OpenCheckTilesCount = OpenCheckTilesCount + 1

OpenCheckTiles(OpenCheckTilesCount) = j End If

If block(j) = 1 Then

If is_black_piece(j, 0) Then If (Image7(black_piece).Tag = "B" Or

Image7(black_piece).Tag = "Q") Then

meron = True j = 64

End If

End If pctr = pctr + 1

End If

End If Next j

If pctr = 1 And meron And andyan Then

GoTo exit_open_check Else

OpenCheckTilesCount = 0

pctr = 0

meron = False

andyan = False End If

Next i

'* * '* ROOK *

'* *

Case "R" '****** pahalang ******

For i = 7 To 9 Step 2 ' 7=downward , 9=upward

For j = kingpos - i To 1 Step -i 'towards left If Image1(kingpos).Tag = Image1(j).Tag Then

If position = j Then

andyan = True End If

If block(j) = 1 Then

If is_black_piece(j, 0) Then If (Image7(black_piece).Tag = "B" Or

Image7(black_piece).Tag = "Q") Then

meron = True j = 1

End If

End If pctr = pctr + 1

End If

End If Next j

If pctr = 1 And meron And andyan Then opencheck = True

GoTo exit_open_check

Else OpenCheckTilesCount = 0

pctr = 0

meron = False andyan = False

End If

For j = kingpos + i To 64 Step i 'towards right If Image1(kingpos).Tag = Image1(j).Tag Then

If position = j Then

andyan = True End If

If block(j) = 1 Then

If is_black_piece(j, 0) Then If (Image7(black_piece).Tag = "B" Or

Image7(black_piece).Tag = "Q") Then

meron = True j = 64

End If

End If

pctr = pctr + 1

End If

End If Next j

If pctr = 1 And meron And andyan Then

opencheck = True GoTo exit_open_check

Else

OpenCheckTilesCount = 0 pctr = 0

meron = False

andyan = False End If

Next i

'>>>>PAGHAHANAP NG PWEDENG LAPAGAN PARA DI OPEN CHECK<<<<

For i = 0 To 1 '0=horizontal, 1=vertical

hakbang = 1 For j = 1 To 8 Step 7 '1=decreasing, 8=increasing

hakbang = hakbang * -1

kl = what_column(kingpos)

Page 82: PC-Based Electronic Chess Board Game

Appendix D D-33

kr = what_row(kingpos)

If i = 0 Then mlimit = kl

Else

mlimit = kr End If

If mlimit <> j Then

For k = mlimit + hakbang To j Step hakbang If i = 0 Then

squares = alamin_ang_pwesto(k, kr)

Else squares = alamin_ang_pwesto(kl, k)

End If

If position = squares Then andyan = True

Else

OpenCheckTilesCount = OpenCheckTilesCount + 1 OpenCheckTiles(OpenCheckTilesCount) = squares

End If

If block(squares) = 1 Then If is_black_piece(squares, 0) Then

If (Image7(black_piece).Tag = "Q" Or

Image7(black_piece).Tag = "R") Then meron = True

k = j

End If End If

pctr = pctr + 1 End If

Next k

If pctr = 1 And meron And andyan Then GoTo exit_open_check

Else

OpenCheckTilesCount = 0 pctr = 0

meron = False

andyan = False End If

End If

Next j Next i

'* *

'* PAWN * '* *

Case "P"

'****** horizontal ****** If Image1(kingpos).Top = Image1(position).Top Then

If kingpos > position Then

For i = position - 8 To 1 Step -8

If Image1(i).Top = Image1(position).Top Then

For j = 1 To 16

If Image1(i).Top = Image7(j).Top And Image1(i).Left = Image7(j).Left Then

If Image7(j).Tag = "Q" Or Image7(j).Tag = "R" Then

For k = i + 8 To kingpos Step 8 If k <> position Then

For l = 1 To 16

If (Image7(l).Top = Image1(k).Top And Image7(l).Left = Image1(k).Left) Or (Image6(l).Top = Image1(k).Top And

Image6(l).Left = Image1(k).Left) Then

blo = True End If

If Not blo Then

opencheck = True End If

Next l

End If Next k

End If

End If

Next j

End If Next i

End If

If kingpos < position Then For i = position + 8 To 64 Step 8

If Image1(i).Top = Image1(position).Top Then

For j = 1 To 16 If Image1(i).Top = Image7(j).Top And Image1(i).Left =

Image7(j).Left Then

If Image7(j).Tag = "Q" Or Image7(j).Tag = "R" Then For k = i - 8 To kingpos Step -8

If k <> position Then

For l = 1 To 16 If (Image7(l).Top = Image1(k).Top And Image7(l).Left =

Image1(k).Left) Or (Image6(l).Top = Image1(k).Top And

Image6(l).Left = Image1(k).Left) Then blo = True

End If

If Not blo Then opencheck = True

End If

Next l End If

Next k

End If End If

Next j End If

Next i

End If End If

'****** vertical ******

If Image1(kingpos).Left = Image1(position).Left Then If kingpos > position Then

For i = position - 1 To 1 Step -1

If Image1(i).Left = Image1(position).Left Then For j = 1 To 16

If Image1(i).Top = Image7(j).Top And Image1(i).Left =

Image7(j).Left Then If Image7(j).Tag = "Q" Or Image7(j).Tag = "R" Then

For k = i + 1 To kingpos

If k <> position Then For l = 1 To 16

If (Image7(l).Top = Image1(k).Top And Image7(l).Left =

Image1(k).Left) Or (Image6(l).Top = Image1(k).Top And Image6(l).Left = Image1(k).Left) Then

blo = True

End If

If Not blo Then

If OPCrow = 2 Then

If block(position - 1) = 0 Then OpenCheckTilesCount = 1

OpenCheckTiles(1) = position - 1

End If If block(position - 2) = 0 Then

OpenCheckTilesCount = 2

OpenCheckTiles(2) = position - 2 End If

Else

If block(position - 1) = 0 Then OpenCheckTilesCount = 1

OpenCheckTiles(1) = position - 1

End If End If

End If

Next l End If

Next k

End If

Page 83: PC-Based Electronic Chess Board Game

Appendix D D-34

End If

Next j End If

Next i

End If If kingpos < position Then

For i = position + 1 To 64

If Image1(i).Left = Image1(position).Left Then For j = 1 To 16

If Image1(i).Top = Image7(j).Top And Image1(i).Left =

Image7(j).Left Then If Image7(j).Tag = "Q" Or Image7(j).Tag = "R" Then

For k = i - 1 To kingpos Step -1

If k <> position Then For l = 1 To 16

If (Image7(l).Top = Image1(k).Top And Image7(l).Left =

Image1(k).Left) Or (Image6(l).Top = Image1(k).Top And Image6(l).Left = Image1(k).Left) Then

blo = True

End If If Not blo Then

If OPCrow = 2 Then

If block(position + 1) = 0 Then OpenCheckTilesCount = 1

OpenCheckTiles(1) = position + 1

End If If block(position + 2) = 0 Then

OpenCheckTilesCount = 2 OpenCheckTiles(2) = position + 2

End If

Else If block(position + 1) = 0 Then

OpenCheckTilesCount = 1

OpenCheckTiles(1) = position + 1 End If

End If

End If Next l

End If

Next k End If

End If

Next j End If

Next i

End If End If

'****** pahalang ******

If Image1(kingpos).Tag = Image1(position).Tag Then

If kingpos > position Then

For i = position - 7 To 1 Step -7

If Image1(i).Tag = Image1(position).Tag Then For j = 1 To 16

If Image1(i).Top = Image7(j).Top And Image1(i).Left =

Image7(j).Left Then If Image7(j).Tag = "Q" Or Image7(j).Tag = "B" Then

For k = i + 7 To kingpos Step 7

If k <> position Then For l = 1 To 16

If (Image7(l).Top = Image1(k).Top And Image7(l).Left =

Image1(k).Left) Or (Image6(l).Top = Image1(k).Top And Image6(l).Left = Image1(k).Left) Then

blo = True

End If If Not blo Then

opencheck = True

End If Next l

End If

Next k

End If

End If Next j

End If

Next i End If

'>>>>>>>>>>>>>>>>>>>>

If position - 9 > 0 Then If block(position - 9) = 1 Then

If is_black_piece(position - 9, 0) And Image1(position -

9).Tag = Image1(kingpos).Tag And Image1(position).Tag = Image1(kingpos).Tag Then

If Image7(black_piece).Tag = "Q" Or

Image7(black_piece).Tag = "B" Then For i = position + 9 To kingpos Step 9

If block(i) = 1 And Image1(i).Tag = Image1(position).Tag

Then If i = kingpos Then

OpenCheckTilesCount = 1

OpenCheckTiles(1) = position - 9 Else

OpenCheckTilesCount = 0

GoTo exit_loop1 End If

End If

Next i exit_loop1:

End If End If

Else

meron = False For j = position - 9 To 1 Step -9

If Image1(j).Tag = Image1(position).Tag Then

If is_black_piece(j, 0) Then If Image7(black_piece).Tag = "Q" Or

Image7(black_piece).Tag = "B" Then

meron = True j = 1

End If

End If 'Else

' j = 1

End If Next j

For j = position + 9 To kingpos Step 9

If Image1(j).Tag = Image1(position).Tag Then If meron Then

opencheck = True

meron = False

GoTo exit_open_check

End If

'Else ' j = kingpos

End If

Next j End If

End If

'>>>>>>>>>>>>> If position + 7 < 65 Then

If block(position + 7) = 1 Then

If is_black_piece(position + 7, 0) And Image1(position + 7).Tag = Image1(kingpos).Tag And Image1(position).Tag =

Image1(kingpos).Tag Then

If Image7(black_piece).Tag = "Q" Or Image7(black_piece).Tag = "B" Then

For i = position - 7 To kingpos Step -7

If block(i) = 1 And Image1(i).Tag = Image1(position).Tag Then

If i = kingpos Then

OpenCheckTilesCount = 1

Page 84: PC-Based Electronic Chess Board Game

Appendix D D-35

OpenCheckTiles(1) = position + 7

Else OpenCheckTilesCount = 0

GoTo exit_loop2

End If End If

Next i

exit_loop2: End If

End If

Else meron = False

For j = position + 7 To 64 Step 7

If Image1(j).Tag = Image1(position).Tag Then If is_black_piece(j, 0) Then

If Image7(black_piece).Tag = "Q" Or

Image7(black_piece).Tag = "B" Then meron = True

j = 1

End If End If

'Else

' j = 1 End If

Next j

For j = position - 7 To kingpos Step -7 If Image1(j).Tag = Image1(position).Tag Then

If meron Then opencheck = True

meron = False

GoTo exit_open_check End If

'Else

' j = kingpos End If

Next j

End If End If

If kingpos < position Then

For i = position + 9 To 64 Step 9 If Image1(i).Left = Image1(position).Left Then

For j = 1 To 16

If Image1(i).Top = Image7(j).Top And Image1(i).Left = Image7(j).Left Then

If Image7(j).Tag = "Q" Or Image7(j).Tag = "B" Then

For k = i - 9 To kingpos Step -9 If k <> position Then

For l = 1 To 16

If (Image7(l).Top = Image1(k).Top And Image7(l).Left =

Image1(k).Left) Or (Image6(l).Top = Image1(k).Top And

Image6(l).Left = Image1(k).Left) Then

blo = True End If

If Not blo Then

opencheck = True End If

Next l

End If Next k

End If

End If Next j

End If

Next i End If

End If

'* * '* QUEEN *

'* *

Case "Q"

'>>>>PAGHAHANAP NG PWEDENG LAPAGAN PARA

DI OPEN CHECK<<<< For i = 7 To 9 Step 2 ' 7=downward , 9=upward

For j = kingpos - i To 1 Step -i 'towards left

If Image1(kingpos).Tag = Image1(j).Tag Then If position = j Then

andyan = True

Else OpenCheckTilesCount = OpenCheckTilesCount + 1

OpenCheckTiles(OpenCheckTilesCount) = j

End If If block(j) = 1 Then

If is_black_piece(j, 0) Then

If (Image7(black_piece).Tag = "B" Or Image7(black_piece).Tag = "Q") Then

meron = True

j = 1 End If

End If

pctr = pctr + 1 End If

End If

Next j If pctr = 1 And meron And andyan Then

GoTo exit_open_check

Else OpenCheckTilesCount = 0

pctr = 0 meron = False

andyan = False

End If For j = kingpos + i To 64 Step i 'towards right

If Image1(kingpos).Tag = Image1(j).Tag Then

If position = j Then andyan = True

Else

OpenCheckTilesCount = OpenCheckTilesCount + 1 OpenCheckTiles(OpenCheckTilesCount) = j

End If

If block(j) = 1 Then If is_black_piece(j, 0) Then

If (Image7(black_piece).Tag = "B" Or

Image7(black_piece).Tag = "Q") Then meron = True

j = 64

End If End If

pctr = pctr + 1

End If

End If

Next j

If pctr = 1 And meron And andyan Then GoTo exit_open_check

Else

OpenCheckTilesCount = 0 pctr = 0

meron = False

andyan = False End If

Next i

'>>>>PAGHAHANAP NG PWEDENG LAPAGAN PARA DI OPEN CHECK<<<<

For i = 0 To 1 '0=horizontal, 1=vertical

hakbang = 1 For j = 1 To 8 Step 7 '1=decreasing, 8=increasing

hakbang = hakbang * -1

kl = what_column(kingpos) kr = what_row(kingpos)

If i = 0 Then

mlimit = kl

Page 85: PC-Based Electronic Chess Board Game

Appendix D D-36

Else

mlimit = kr End If

If mlimit <> j Then

For k = mlimit + hakbang To j Step hakbang If i = 0 Then

squares = alamin_ang_pwesto(k, kr)

Else squares = alamin_ang_pwesto(kl, k)

End If

If position = squares Then andyan = True

Else

OpenCheckTilesCount = OpenCheckTilesCount + 1 OpenCheckTiles(OpenCheckTilesCount) = squares

End If

If block(squares) = 1 Then If is_black_piece(squares, 0) Then

If (Image7(black_piece).Tag = "Q" Or

Image7(black_piece).Tag = "R") Then meron = True

k = j

End If End If

pctr = pctr + 1

End If Next k

If pctr = 1 And meron And andyan Then GoTo exit_open_check

Else

OpenCheckTilesCount = 0 pctr = 0

meron = False

andyan = False End If

End If

Next j Next i

End Select

End If End If

'*****************************

If blackturn Then For i = 1 To 64

If Image7(13).Top = Image1(i).Top And Image7(13).Left =

Image1(i).Left Then kingpos = i

i = 64

End If

Next i

If piece <> "K" Then Select Case piece

'* *

'* black knight * '* *

Case "N"

For i = 0 To 1 '0=horizontal, 1=vertical hakbang = 1

For j = 1 To 8 Step 7 '1=decreasing, 8=increasing

hakbang = hakbang * -1 kl = what_column(kingpos)

kr = what_row(kingpos)

If i = 0 Then mlimit = kl

Else

mlimit = kr End If

If mlimit <> j Then

For k = mlimit + hakbang To j Step hakbang

If i = 0 Then

squares = alamin_ang_pwesto(k, kr) Else

squares = alamin_ang_pwesto(kl, k)

End If If position = squares Then

andyan = True

End If

If block(squares) = 1 Then

If is_white_piece(squares, 0) Then If (Image6(white_piece).Tag = "Q" Or

Image6(white_piece).Tag = "R") Then

meron = True k = j

End If

End If pctr = pctr + 1

End If

Next k If pctr = 1 And meron And andyan Then

opencheck = True

GoTo exit_open_check Else

OpenCheckTilesCount = 0

pctr = 0 meron = False

andyan = False End If

End If

Next j Next i

'****** pahalang ******

For i = 7 To 9 Step 2 ' 7=downward , 9=upward For j = kingpos - i To 1 Step -i 'towards left

If Image1(kingpos).Tag = Image1(j).Tag Then

If position = j Then andyan = True

End If

If block(j) = 1 Then If is_white_piece(j, 0) Then

If (Image6(white_piece).Tag = "B" Or

Image6(white_piece).Tag = "Q") Then meron = True

j = 1

End If End If

pctr = pctr + 1

End If

End If

Next j

If pctr = 1 And meron And andyan Then opencheck = True

GoTo exit_open_check

Else OpenCheckTilesCount = 0

pctr = 0

meron = False andyan = False

End If

For j = kingpos + i To 64 Step i 'towards right If Image1(kingpos).Tag = Image1(j).Tag Then

If position = j Then

andyan = True End If

If block(j) = 1 Then

If is_white_piece(j, 0) Then If (Image6(white_piece).Tag = "B" Or

Image6(white_piece).Tag = "Q") Then

meron = True

Page 86: PC-Based Electronic Chess Board Game

Appendix D D-37

j = 64

End If End If

pctr = pctr + 1

End If End If

Next j

If pctr = 1 And meron And andyan Then opencheck = True

GoTo exit_open_check

Else OpenCheckTilesCount = 0

pctr = 0

meron = False andyan = False

End If

Next i '* *

'* BLACK BISHOP *

'* * Case "B"

For i = 0 To 1 '0=horizontal, 1=vertical

hakbang = 1 For j = 1 To 8 Step 7 '1=decreasing, 8=increasing

hakbang = hakbang * -1

kl = what_column(kingpos) kr = what_row(kingpos)

If i = 0 Then mlimit = kl

Else

mlimit = kr End If

If mlimit <> j Then

For k = mlimit + hakbang To j Step hakbang If i = 0 Then

squares = alamin_ang_pwesto(k, kr)

Else squares = alamin_ang_pwesto(kl, k)

End If

If position = squares Then andyan = True

End If If block(squares) = 1 Then

If is_white_piece(squares, 0) Then

If (Image6(white_piece).Tag = "Q" Or Image6(white_piece).Tag = "R") Then

meron = True

k = j

End If

End If

pctr = pctr + 1 End If

Next k

If pctr = 1 And meron And andyan Then opencheck = True

GoTo exit_open_check

Else OpenCheckTilesCount = 0

pctr = 0

meron = False andyan = False

End If

End If Next j

Next i

'>>>>PAGHAHANAP NG PWEDENG LAPAGAN PARA DI OPEN CHECK<<<<

For i = 7 To 9 Step 2 ' 7=downward , 9=upward

For j = kingpos - i To 1 Step -i 'towards left

If Image1(kingpos).Tag = Image1(j).Tag Then

If position = j Then andyan = True

Else

OpenCheckTilesCount = OpenCheckTilesCount + 1 OpenCheckTiles(OpenCheckTilesCount) = j

End If

If block(j) = 1 Then If is_white_piece(j, 0) Then

If (Image6(white_piece).Tag = "B" Or

Image6(white_piece).Tag = "Q") Then meron = True

j = 1

End If End If

pctr = pctr + 1

End If End If

Next j

If pctr = 1 And meron And andyan Then GoTo exit_open_check

Else

OpenCheckTilesCount = 0 pctr = 0

meron = False

andyan = False End If

For j = kingpos + i To 64 Step i 'towards right If Image1(kingpos).Tag = Image1(j).Tag Then

If position = j Then

andyan = True Else

OpenCheckTilesCount = OpenCheckTilesCount + 1

OpenCheckTiles(OpenCheckTilesCount) = j End If

If block(j) = 1 Then

If is_white_piece(j, 0) Then If (Image6(white_piece).Tag = "B" Or

Image6(white_piece).Tag = "Q") Then

meron = True j = 64

End If

End If pctr = pctr + 1

End If

End If Next j

If pctr = 1 And meron And andyan Then

GoTo exit_open_check

Else

OpenCheckTilesCount = 0

pctr = 0 meron = False

andyan = False

End If Next i

'* *

'* BLACK ROOK * '* *

Case "R"

'pahalang For i = 7 To 9 Step 2 ' 7=downward , 9=upward

For j = kingpos - i To 1 Step -i 'towards left

If Image1(kingpos).Tag = Image1(j).Tag Then If position = j Then

andyan = True

End If If block(j) = 1 Then

If is_white_piece(j, 0) Then

Page 87: PC-Based Electronic Chess Board Game

Appendix D D-38

If (Image6(white_piece).Tag = "B" Or

Image6(white_piece).Tag = "Q") Then meron = True

j = 1

End If End If

pctr = pctr + 1

End If End If

Next j

If pctr = 1 And meron And andyan Then opencheck = True

GoTo exit_open_check

Else OpenCheckTilesCount = 0

pctr = 0

meron = False andyan = False

End If

For j = kingpos + i To 64 Step i 'towards right If Image1(kingpos).Tag = Image1(j).Tag Then

If position = j Then

andyan = True End If

If block(j) = 1 Then

If is_white_piece(j, 0) Then If (Image6(white_piece).Tag = "B" Or

Image6(white_piece).Tag = "Q") Then meron = True

j = 64

End If End If

pctr = pctr + 1

End If End If

Next j

If pctr = 1 And meron And andyan Then opencheck = True

GoTo exit_open_check

Else OpenCheckTilesCount = 0

pctr = 0

meron = False andyan = False

End If

Next i '>>>>PAGHAHANAP NG PWEDENG LAPAGAN PARA

DI OPEN CHECK<<<<

For i = 0 To 1 '0=horizontal, 1=vertical

hakbang = 1

For j = 1 To 8 Step 7 '1=decreasing, 8=increasing

hakbang = hakbang * -1 kl = what_column(kingpos)

kr = what_row(kingpos)

If i = 0 Then mlimit = kl

Else

mlimit = kr End If

If mlimit <> j Then

For k = mlimit + hakbang To j Step hakbang If i = 0 Then

squares = alamin_ang_pwesto(k, kr)

Else squares = alamin_ang_pwesto(kl, k)

End If

If position = squares Then andyan = True

Else

OpenCheckTilesCount = OpenCheckTilesCount + 1

OpenCheckTiles(OpenCheckTilesCount) = squares

End If If block(squares) = 1 Then

If is_white_piece(squares, 0) Then

If (Image6(white_piece).Tag = "Q" Or Image6(white_piece).Tag = "R") Then

meron = True

k = j End If

End If

pctr = pctr + 1 End If

Next k

If pctr = 1 And meron And andyan Then GoTo exit_open_check

Else

OpenCheckTilesCount = 0 pctr = 0

meron = False

andyan = False End If

End If

Next j Next i

'* *

'* BLACK PAWN * '* *

Case "P" '****** horizontal ******

If Image1(kingpos).Top = Image1(position).Top Then

If kingpos > position Then For i = position - 8 To 1 Step -8

If Image1(i).Top = Image1(position).Top Then

For j = 1 To 16 If Image1(i).Top = Image6(j).Top And Image1(i).Left =

Image6(j).Left Then

If Image6(j).Tag = "Q" Or Image6(j).Tag = "R" Then For k = i + 8 To kingpos Step 8

If k <> position Then

For l = 1 To 16 If (Image7(l).Top = Image1(k).Top And Image7(l).Left =

Image1(k).Left) Or (Image6(l).Top = Image1(k).Top And

Image6(l).Left = Image1(k).Left) Then blo = True

End If

If Not blo Then opencheck = True

End If

Next l

End If

Next k

End If End If

Next j

End If Next i

End If

If kingpos < position Then

For i = position + 8 To 64 Step 8

If Image1(i).Top = Image1(position).Top Then For j = 1 To 16

If Image1(i).Top = Image6(j).Top And Image1(i).Left =

Image6(j).Left Then If Image6(j).Tag = "Q" Or Image6(j).Tag = "R" Then

For k = i - 8 To kingpos Step -8

If k <> position Then For l = 1 To 16

Page 88: PC-Based Electronic Chess Board Game

Appendix D D-39

If (Image7(l).Top = Image1(k).Top And Image7(l).Left =

Image1(k).Left) Or (Image6(l).Top = Image1(k).Top And Image6(l).Left = Image1(k).Left) Then

blo = True

End If If Not blo Then

opencheck = True

End If Next l

End If

Next k End If

End If

Next j End If

Next i

End If End If

'****** vertical ******

If Image1(kingpos).Left = Image1(position).Left Then If kingpos > position Then

For i = position - 1 To 1 Step -1

If Image1(i).Left = Image1(position).Left Then For j = 1 To 16

If Image1(i).Top = Image6(j).Top And Image1(i).Left =

Image6(j).Left Then If Image6(j).Tag = "Q" Or Image6(j).Tag = "R" Then

For k = i + 1 To kingpos If k <> position Then

For l = 1 To 16

If (Image7(l).Top = Image1(k).Top And Image7(l).Left = Image1(k).Left) Or (Image6(l).Top = Image1(k).Top And

Image6(l).Left = Image1(k).Left) Then

blo = True End If

If Not blo Then

If OPCrow = 7 Then If block(position + 1) = 0 Then

OpenCheckTilesCount = 1

OpenCheckTiles(1) = position + 1 End If

If block(position + 2) = 0 Then

OpenCheckTilesCount = 2 OpenCheckTiles(2) = position + 2

End If

Else If block(position + 1) = 0 Then

OpenCheckTilesCount = 1

OpenCheckTiles(1) = position + 1

End If

End If

End If Next l

End If

Next k End If

End If

Next j End If

Next i

End If If kingpos < position Then

For i = position + 1 To 64

If Image1(i).Left = Image1(position).Left Then For j = 1 To 16

If Image1(i).Top = Image6(j).Top And Image1(i).Left =

Image6(j).Left Then If Image6(j).Tag = "Q" Or Image6(j).Tag = "R" Then

For k = i - 1 To kingpos Step -1

If k <> position Then

For l = 1 To 16

If (Image7(l).Top = Image1(k).Top And Image7(l).Left = Image1(k).Left) Or (Image6(l).Top = Image1(k).Top And

Image6(l).Left = Image1(k).Left) Then

blo = True End If

If Not blo Then

If OPCrow = 7 Then If block(position + 1) = 0 Then

OpenCheckTilesCount = 1

OpenCheckTiles(1) = position + 1 End If

If block(position + 2) = 0 Then

OpenCheckTilesCount = 2 OpenCheckTiles(2) = position + 2

End If

Else If block(position + 1) = 0 Then

OpenCheckTilesCount = 1

OpenCheckTiles(1) = position + 1 End If

End If

End If Next l

End If

Next k End If

End If Next j

End If

Next i End If

End If

'****** pahalang ****** If Image1(kingpos).Tag = Image1(position).Tag Then

If kingpos > position Then

For i = position - 9 To 1 Step -9 If Image1(i).Tag = Image1(position).Tag Then

For j = 1 To 16

If Image1(i).Top = Image6(j).Top And Image1(i).Left = Image6(j).Left Then

If Image6(j).Tag = "Q" Or Image6(j).Tag = "B" Then

For k = i + 9 To kingpos Step 9 If k <> position Then

For l = 1 To 16

If (Image7(l).Top = Image1(k).Top And Image7(l).Left = Image1(k).Left) Or (Image6(l).Top = Image1(k).Top And

Image6(l).Left = Image1(k).Left) Then

blo = True

End If

If Not blo Then

opencheck = True End If

Next l

End If Next k

End If

End If Next j

End If

Next i End If

'>>>>>>>>>>>>>>>>>>>>

If position - 7 > 0 Then If block(position - 7) = 1 Then

If is_white_piece(position - 7, 0) And Image1(position -

7).Tag = Image1(kingpos).Tag And Image1(position).Tag = Image1(kingpos).Tag Then

If Image7(white_piece).Tag = "Q" Or

Image7(white_piece).Tag = "B" Then

Page 89: PC-Based Electronic Chess Board Game

Appendix D D-40

For i = position + 7 To kingpos Step 7

If block(i) = 1 And Image1(i).Tag = Image1(position).Tag Then

If i = kingpos Then

OpenCheckTilesCount = 1 OpenCheckTiles(1) = position - 7

Else

OpenCheckTilesCount = 0 GoTo exit_loop1

End If

End If Next i

exit_loop1b:

End If End If

Else

meron = False For j = position - 7 To 1 Step -7

If Image1(j).Tag = Image1(position).Tag Then

If is_white_piece(j, 0) Then If Image6(white_piece).Tag = "Q" Or

Image6(white_piece).Tag = "B" Then

meron = True j = 1

End If

End If 'Else

' j = 1 End If

Next j

For j = position + 7 To kingpos Step 7 If Image1(j).Tag = Image1(position).Tag Then

If meron Then

opencheck = True meron = False

GoTo exit_open_check

End If 'Else

' j = kingpos

End If Next j

End If

End If '>>>>>>>>>>>>>

If position + 9 < 65 Then

If block(position + 9) = 1 Then If is_white_piece(position + 9, 0) And Image1(position +

9).Tag = Image1(kingpos).Tag And Image1(position).Tag =

Image1(kingpos).Tag Then

If Image6(white_piece).Tag = "Q" Or

Image6(white_piece).Tag = "B" Then

For i = position - 9 To kingpos Step -9 If block(i) = 1 And Image1(i).Tag = Image1(position).Tag

Then

If i = kingpos Then OpenCheckTilesCount = 1

OpenCheckTiles(1) = position + 9

Else OpenCheckTilesCount = 0

GoTo exit_loop2

End If End If

Next i

exit_loop2b: End If

End If

Else meron = False

For j = position + 9 To 64 Step 9

If Image1(j).Tag = Image1(position).Tag Then

If is_white_piece(j, 0) Then

If Image6(white_piece).Tag = "Q" Or Image6(white_piece).Tag = "B" Then

meron = True

j = 1 End If

End If

'Else ' j = 1

End If

Next j For j = position - 9 To kingpos Step -9

If Image1(j).Tag = Image1(position).Tag Then

If meron Then opencheck = True

meron = False

GoTo exit_open_check End If

'Else

' j = kingpos End If

Next j

End If End If

If kingpos < position Then

For i = position + 7 To 64 Step 7 If Image1(i).Left = Image1(position).Left Then

For j = 1 To 16 If Image1(i).Top = Image6(j).Top And Image1(i).Left =

Image6(j).Left Then

If Image6(j).Tag = "Q" Or Image6(j).Tag = "B" Then For k = i - 7 To kingpos Step -7

If k <> position Then

For l = 1 To 16 If (Image7(l).Top = Image1(k).Top And Image7(l).Left =

Image1(k).Left) Or (Image6(l).Top = Image1(k).Top And

Image6(l).Left = Image1(k).Left) Then blo = True

End If

If Not blo Then opencheck = True

End If

Next l End If

Next k

End If End If

Next j

End If

Next i

End If

End If '* *

'* BLACK QUEEN *

'* * Case "Q"

'>>>>PAGHAHANAP NG PWEDENG LAPAGAN PARA

DI OPEN CHECK<<<< For i = 7 To 9 Step 2 ' 7=downward , 9=upward

For j = kingpos - i To 1 Step -i 'towards left

If Image1(kingpos).Tag = Image1(j).Tag Then If position = j Then

andyan = True

Else OpenCheckTilesCount = OpenCheckTilesCount + 1

OpenCheckTiles(OpenCheckTilesCount) = j

End If If block(j) = 1 Then

If is_white_piece(j, 0) Then

Page 90: PC-Based Electronic Chess Board Game

Appendix D D-41

If (Image6(white_piece).Tag = "B" Or

Image6(white_piece).Tag = "Q") Then meron = True

j = 1

End If End If

pctr = pctr + 1

End If End If

Next j

If pctr = 1 And meron And andyan Then GoTo exit_open_check

Else

OpenCheckTilesCount = 0 pctr = 0

meron = False

andyan = False End If

For j = kingpos + i To 64 Step i 'towards right

If Image1(kingpos).Tag = Image1(j).Tag Then If position = j Then

andyan = True

Else OpenCheckTilesCount = OpenCheckTilesCount + 1

OpenCheckTiles(OpenCheckTilesCount) = j

End If If block(j) = 1 Then

If is_white_piece(j, 0) Then If (Image6(white_piece).Tag = "B" Or

Image6(white_piece).Tag = "Q") Then

meron = True j = 64

End If

End If pctr = pctr + 1

End If

End If Next j

If pctr = 1 And meron And andyan Then

GoTo exit_open_check Else

OpenCheckTilesCount = 0

pctr = 0 meron = False

andyan = False

End If Next i

'>>>>PAGHAHANAP NG PWEDENG LAPAGAN PARA

DI OPEN CHECK<<<<

For i = 0 To 1 '0=horizontal, 1=vertical

hakbang = 1

For j = 1 To 8 Step 7 '1=decreasing, 8=increasing hakbang = hakbang * -1

kl = what_column(kingpos)

kr = what_row(kingpos) If i = 0 Then

mlimit = kl

Else mlimit = kr

End If

If mlimit <> j Then For k = mlimit + hakbang To j Step hakbang

If i = 0 Then

squares = alamin_ang_pwesto(k, kr) Else

squares = alamin_ang_pwesto(kl, k)

End If If position = squares Then

andyan = True

Else

OpenCheckTilesCount = OpenCheckTilesCount + 1

OpenCheckTiles(OpenCheckTilesCount) = squares End If

If block(squares) = 1 Then

If is_white_piece(squares, 0) Then If (Image6(white_piece).Tag = "Q" Or

Image6(white_piece).Tag = "R") Then

meron = True k = j

End If

End If pctr = pctr + 1

End If

Next k If pctr = 1 And meron And andyan Then

GoTo exit_open_check

Else OpenCheckTilesCount = 0

pctr = 0

meron = False andyan = False

End If

End If Next j

Next i

End Select End If

End If exit_open_check:

End Function

Private Sub blink_timer_Timer() If draw Then

If Not blink_trigger Then

blink_all blink_trigger = Not blink_trigger

Else

reset_changed_tiles blink_trigger = Not blink_trigger

End If

End If If checkmate Then

If Not blink_trigger Then

blink_loser blink_trigger = Not blink_trigger

Else

reset_changed_tiles blink_trigger = Not blink_trigger

End If

End If

End Sub

Private Sub cmd_next_Click() run_command

End Sub

Private Sub cmd_prev_Click()

step_back

End Sub

Private Sub Command2_Click()

Dim ind As Integer piecechose = -1

For i = 1 To 4

If image10(i).BorderStyle = 1 Then piecechose = i

End If

Next i If piecechose > -1 Then

If bpicked Then

Image7(piecenum).Picture = image10(piecechose).Picture

Page 91: PC-Based Electronic Chess Board Game

Appendix D D-42

Image7(piecenum).Tag = image10(piecechose).Tag

piecepromoted = image10(piecechose).Tag Command2.Visible = False

For i = 1 To 4

image10(i).Visible = False image10(i).BorderStyle = 0

Next i

Label3.Visible = False 'checked = check

If gamemode = "Amateur" Then

Call blackturnoff(ind) Else

If ProSw = 110 Then

Call blackturnoff(ind) End If

End If

Timer2.Enabled = True Timer3.Enabled = True

End If

If picked Then

Image6(piecenum).Picture = image10(piecechose).Picture

Image6(piecenum).Tag = image10(piecechose).Tag piecepromoted = image10(piecechose).Tag

Command2.Visible = False

For i = 1 To 4 image10(i).Visible = False

image10(i).BorderStyle = 0 Next i

Label3.Visible = False

'checked = check If gamemode = "Amateur" Then

Call whiteturnoff(ind)

Else If ProSw = 94 Then

Call whiteturnoff(ind)

End If End If

Timer2.Enabled = True

Timer3.Enabled = True End If

End If

End Sub

Private Sub Form_Load()

boolforpatong = False bturn2 = 0

trgr = True

trigger = False

counter = 0

column = 0

opl = 0 posopl = 0

Out 890, 41

kingblackmoved = False kingwhitemoved = False

rightrookwhitemoved = False

leftrookwhitemoved = False rightrookblackmoved = False

leftrookblackmoved = False

blackturn = False whiteturn = False

picked = False

bpicked = False position = 0

castling = False

checked = False move_count = 1

mcastling = True

castling_queen_side = True

castling_king_side = True

mcastlingb = True castling_queen_sideb = True

castling_king_sideb = True

checkmate = False draw = False

takboctr = 0

kukai = "" run_cnt = 0

hula = False

ppp = 0 Call load_color

Frame1.Visible = False

lblmessage.Top = Me.Top lblmessage.Left = Me.Width

For t = 1 To 8 whitepawnmoved(t) = False

blackpawnmoved(t) = False

enpassantpiecew(t) = False enpassantpieceb(t) = False

Next

lst_moves.Clear

For i = 0 To 1

Label7(i).Caption = "" Next i

For i = 1 To 8 Image7(i).Picture = LoadPicture(App.Path &

"/images/pionblack.gif")

Image6(i).Picture = LoadPicture(App.Path & "/images/pionwhite.gif")

Image7(i).Tag = "P"

Image6(i).Tag = "P" enpassantpiecew(i) = False

enpassantpieceb(i) = False

Next i

g = 0

For t = 7 To 63 Step 8 g = g + 1

Image6(g).Top = Image1(t).Top

Image6(g).Left = Image1(t).Left Next

g = 8 For t = 8 To 64 Step 8

g = g + 1

Image6(g).Top = Image1(t).Top

Image6(g).Left = Image1(t).Left

Next

g = 0

For t = 2 To 58 Step 8

g = g + 1 Image7(g).Top = Image1(t).Top

Image7(g).Left = Image1(t).Left

Next

g = 8

For t = 1 To 57 Step 8 g = g + 1

Image7(g).Top = Image1(t).Top

Image7(g).Left = Image1(t).Left Next

For i = 1 To 16 Image6(i).Visible = False

Image7(i).Visible = False

Next i

Page 92: PC-Based Electronic Chess Board Game

Appendix D D-43

Label10.Caption = ""

End Sub

Private Sub Form_Unload(Cancel As Integer)

End End Sub

Private Sub Image10_Click(Index As Integer) For i = 1 To 4

image10(i).BorderStyle = 0

Next i image10(Index).BorderStyle = 1

End Sub

Private Function blackturnoff(ind As Integer)

Out 890, 35

Call resetenpassant whiteturn = True

blackturn = False

bpicked = False Call findlabel(ind)

moveto = Label7(0).Caption

reset_changed_tiles checked = check

Call append_list

If checked Then If checkmate_ba Then

Timer2.Enabled = False Timer3.Enabled = False

Timer6.Enabled = False

blink_timer.Enabled = True lst_moves.AddItem " 0-1"

MsgBox ("Checkmate Black Wins!")

End If Else

If stalemate_ba Then

Timer2.Enabled = False Timer3.Enabled = False

Timer6.Enabled = False

blink_timer.Enabled = True lst_moves.AddItem " 1/2-1/2"

MsgBox ("Stalemate Draw!")

End If End If

If perpetual_check Then

Timer2.Enabled = False Timer3.Enabled = False

blink_timer.Enabled = True

lst_moves.AddItem " 1/2-1/2"

MsgBox ("Draw!")

MsgBox ("The positions has been repeated three times!")

End If '(1).FillColor = &H0&

Call movesave

If mnuAutoSave.Caption = "AutoSave OFF" Then Call autoseyb

End If

Label7(1).Caption = "W" Out 890, 34

End Function

Private Function blink_all() For i = 1 To 64

If block(i) = 1 Then

Image1(i).Picture = LoadPicture(App.Path & "\images\black_glow.jpg")

inc_changed_tiles (i)

End If Next i

End Function

Private Function blink_loser()

Dim i As Integer

If whiteturn Then For i = 1 To 64

If is_white_piece(i, 0) And block(i) = 1 Then

If white_piece = 13 Then Image1(i).Picture = LoadPicture(App.Path &

"\images\on_threat.jpg")

inc_changed_tiles (i) End If

End If

Next i End If

If blackturn Then

For i = 1 To 64 If is_black_piece(i, 0) And block(i) = 1 Then

If black_piece = 13 Then

Image1(i).Picture = LoadPicture(App.Path & "\images\on_threat.jpg")

inc_changed_tiles (i)

End If End If

Next i

End If End Function

Private Function movesave()

Open App.Path & "\movesave\" & currentsavefile & ".txt" For Output As #1

For i = 0 To lst_moves.ListCount Print #1, lst_moves.List(i)

Next i

Close #1 End Function

Private Function whiteturnoff(ind As Integer)

Out 890, 35 Call resetenpassant

whiteturn = False

blackturn = True picked = False

Call findlabel(ind)

moveto = Label7(0).Caption reset_changed_tiles

checked = check

Call append_list If checked Then

If checkmate_ba Then

Timer2.Enabled = False Timer3.Enabled = False

Timer6.Enabled = False

blink_timer.Enabled = True

lst_moves.AddItem " 1-0"

MsgBox ("Checkmate White Wins!")

End If Else

If stalemate_ba Then

Timer2.Enabled = False Timer3.Enabled = False

Timer6.Enabled = False

blink_timer.Enabled = True lst_moves.AddItem " 1/2-1/2"

MsgBox ("Stalemate Draw!")

End If End If

If perpetual_check Then

Timer2.Enabled = False Timer3.Enabled = False

blink_timer.Enabled = True

lst_moves.AddItem " 1/2-1/2" MsgBox ("Draw!")

MsgBox ("The positions has been repeated three times!")

End If

Page 93: PC-Based Electronic Chess Board Game

Appendix D D-44

'(0).FillColor = &H0&

Call movesave If mnuAutoSave.Caption = "AutoSave OFF" Then

Call autoseyb

End If Label7(1).Caption = "B"

Out 890, 34

End Function

Private Function piecemoves(ind As Integer)

If bpicked Then If gamemode = "Amateur" Then

If ind = position Then

Image7(piecenum).Left = Image1(ind).Left Image7(piecenum).Top = Image1(ind).Top

Call reset_changed_tiles

bpicked = False End If

End If

Select Case piece Case "P"

If opponentpiecelifted Then ' |||||||| kain |||||||

If Not pawnpromote Then ' |||||||| not promoted ||||||||||| If ind = position - 7 Or ind = position + 9 Then

If ind = posopl Then

If checked Then ' kung check If naharangan_ba(ind) Then ' kung mahaharangan yung

nagcheck Image7(piecenum).Left = Image1(ind).Left

Image7(piecenum).Top = Image1(ind).Top

opponentpiecelifted = False

blackpawnmoved(piecenum) = True

If gamemode = "Amateur" Then Call blackturnoff(ind)

Else

ProTaba = ind protime.Enabled = True

End If

GoTo ExitPieceMoves Else

kukai = "Still on Check!"

Timer6.Enabled = True End If

Else ' hindi check

Image7(piecenum).Left = Image1(ind).Left Image7(piecenum).Top = Image1(ind).Top

opponentpiecelifted = False

blackpawnmoved(piecenum) = True

If gamemode = "Amateur" Then

Call blackturnoff(ind) Else

ProTaba = ind

protime.Enabled = True End If

GoTo ExitPieceMoves

End If Else 'passed pawn

If (posopl = position - 8 Or posopl = position + 8) And

beyond(position) Then If enpassantpiecew(opl) Then

If posdes = ind Then

If checked Then 'check If naharangan_ba(ind) Then

Image7(piecenum).Left = Image1(ind).Left

Image7(piecenum).Top = Image1(ind).Top

opponentpiecelifted = False

blackpawnmoved(piecenum) = True

If gamemode = "Amateur" Then

Call blackturnoff(ind) Else

ProTaba = ind

protime.Enabled = True End If

GoTo ExitPieceMoves

Else kukai = "Still on Check!"

Timer6.Enabled = True

End If Else 'check

Image7(piecenum).Left = Image1(ind).Left

Image7(piecenum).Top = Image1(ind).Top

opponentpiecelifted = False

blackpawnmoved(piecenum) = True If gamemode = "Amateur" Then

Call blackturnoff(ind)

Else ProTaba = ind

protime.Enabled = True

End If GoTo ExitPieceMoves

End If

Else kukai = "Illegal Move!"

Timer6.Enabled = True End If

End If

End If End If

Else

kukai = "Illegal Move!" Timer6.Enabled = True

End If

Else 'pawn promoted If (ind = position - 7 Or ind = position + 9) Then

If ind = posopl Then 'kain lang

If checked Then If naharangan_ba(ind) Then

Image7(piecenum).Left = Image1(ind).Left

Image7(piecenum).Top = Image1(ind).Top pawnpromotion (ind)

opponentpiecelifted = False

blackpawnmoved(piecenum) = True GoTo ExitPieceMoves

Else

kukai = "Still on Check!"

Timer6.Enabled = True

End If

Else Image7(piecenum).Left = Image1(ind).Left

Image7(piecenum).Top = Image1(ind).Top

pawnpromotion (ind) opponentpiecelifted = False

blackpawnmoved(piecenum) = True

GoTo ExitPieceMoves End If

Else 'passed pawn

If (posopl = position - 8 Or posopl = position + 8) And beyond(position) Then

If enpassantpiecew(opl) Then

If posdes = ind Then If checked Then

If naharangan_ba(ind) Then

Image7(piecenum).Left = Image1(ind).Left Image7(piecenum).Top = Image1(ind).Top

pawnpromotion (ind)

opponentpiecelifted = False

Page 94: PC-Based Electronic Chess Board Game

Appendix D D-45

blackpawnmoved(piecenum) = True

GoTo ExitPieceMoves Else

kukai = "Still on Check!"

Timer6.Enabled = True End If

Else

Image7(piecenum).Left = Image1(ind).Left Image7(piecenum).Top = Image1(ind).Top

pawnpromotion (ind)

opponentpiecelifted = False blackpawnmoved(piecenum) = True

GoTo ExitPieceMoves

End If Else

kukai = "Illegal Move!"

Timer6.Enabled = True End If

End If

End If End If

Else

kukai = "Illegal Move!" Timer6.Enabled = True

End If

End If Else 'galaw lang

If Not pawnpromoted Then If ind = position + 1 Then

If checked Then

If naharangan_ba(ind) Then Image7(piecenum).Left = Image1(ind).Left

Image7(piecenum).Top = Image1(ind).Top

opponentpiecelifted = False

blackpawnmoved(piecenum) = True

If gamemode = "Amateur" Then Call blackturnoff(ind)

Else

ProTaba = ind protime.Enabled = True

End If

GoTo ExitPieceMoves Else

kukai = "Still on Check!"

Timer6.Enabled = True End If

Else

Image7(piecenum).Left = Image1(ind).Left

Image7(piecenum).Top = Image1(ind).Top

opponentpiecelifted = False blackpawnmoved(piecenum) = True

If gamemode = "Amateur" Then

Call blackturnoff(ind) Else

ProTaba = ind

protime.Enabled = True End If

GoTo ExitPieceMoves

End If Else

If ind = position + 2 Then

If Not blackpawnmoved(piecenum) Then If checked Then

If naharangan_ba(ind) Then

Image7(piecenum).Left = Image1(ind).Left Image7(piecenum).Top = Image1(ind).Top

blackpawnmoved(piecenum) = True

For i = 1 To 8

If ind + 8 < 65 Then

If Image1(ind + 8).Top = Image6(i).Top And Image1(ind + 8).Left = Image6(i).Left Then

enpassantpieceb(piecenum) = True

End If End If

If ind - 8 > 0 Then

If Image1(ind - 8).Top = Image6(i).Top And Image1(ind - 8).Left = Image6(i).Left Then

enpassantpieceb(piecenum) = True

End If End If

Next i

If gamemode = "Amateur" Then Call blackturnoff(ind)

Else

ProTaba = ind protime.Enabled = True

End If

Else kukai = "Still on CHeck!"

Timer6.Enabled = True

End If Else

For j = 1 To 16

If (Image1(ind).Top = Image7(j).Top And Image1(ind).Left = Image7(j).Left) Or (Image1(ind).Top = Image6(j).Top And

Image1(ind).Left = Image6(j).Left) Then boolforpatong = True

End If

Next j

If Not boolforpatong Then

Image7(piecenum).Left = Image1(ind).Left Image7(piecenum).Top = Image1(ind).Top

blackpawnmoved(piecenum) = True For i = 1 To 8

If ind + 8 < 65 Then

If Image1(ind + 8).Top = Image6(i).Top And Image1(ind + 8).Left = Image6(i).Left Then

enpassantpieceb(piecenum) = True

End If End If

If ind - 8 > 0 Then

If Image1(ind - 8).Top = Image6(i).Top And Image1(ind - 8).Left = Image6(i).Left Then

enpassantpieceb(piecenum) = True

End If

End If

Next i

If gamemode = "Amateur" Then Call blackturnoff(ind)

Else

ProTaba = ind protime.Enabled = True

End If

End If End If

End If

Else kukai = "Illegal Move!"

Timer6.Enabled = True

End If End If

Else

If ind = position + 1 Then If checked Then

If naharangan_ba(ind) Then

Image7(piecenum).Left = Image1(ind).Left

Page 95: PC-Based Electronic Chess Board Game

Appendix D D-46

Image7(piecenum).Top = Image1(ind).Top

pawnpromotion (ind) opponentpiecelifted = False

blackpawnmoved(piecenum) = True

Else kukai = "Still on Check!"

Timer6.Enabled = True

End If Else

Image7(piecenum).Left = Image1(ind).Left

Image7(piecenum).Top = Image1(ind).Top pawnpromotion (ind)

opponentpiecelifted = False

blackpawnmoved(piecenum) = True End If

Else

kukai = "Illegal Move!" Timer6.Enabled = True

End If

End If End If

Case "N"

If opponentpiecelifted Then If ind = posopl Then

If checked Then

If naharangan_ba(ind) Then Image7(piecenum).Top = Image1(ind).Top

Image7(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False

If gamemode = "Amateur" Then Call blackturnoff(ind)

Else

ProTaba = ind protime.Enabled = True

End If

Else

kukai = "Still on CHeck!"

Timer6.Enabled = True End If

Else

Image7(piecenum).Top = Image1(ind).Top Image7(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False If gamemode = "Amateur" Then

Call blackturnoff(ind)

Else

ProTaba = ind

protime.Enabled = True

End If End If

Else

kukai = "Illegal Move!" Timer6.Enabled = True

End If

Else For i = 1 To 16

If Image1(ind).Top = Image7(i).Top And Image1(ind).Left =

Image7(i).Left Then boolforpatong = True

End If

Next i If Not boolforpatong Then

If Image1(position).Tag <> Image1(ind).Tag And (ind =

position - 6 Or ind = position - 10 Or ind = position - 15 Or ind = position - 17 Or ind = position + 6 Or ind = position +

10 Or ind = position + 15 Or ind = position + 17) Then

If checked Then

If naharangan_ba(ind) Then

Image7(piecenum).Top = Image1(ind).Top Image7(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False If gamemode = "Amateur" Then

Call blackturnoff(ind)

Else ProTaba = ind

protime.Enabled = True

End If Else

kukai = "Still on Check!"

Timer6.Enabled = True End If

Else

Image7(piecenum).Top = Image1(ind).Top Image7(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False If gamemode = "Amateur" Then

Call blackturnoff(ind)

Else ProTaba = ind

protime.Enabled = True

End If End If

Else kukai = "Illegal Move!"

Timer6.Enabled = True

End If End If

End If

Case "K" If opponentpiecelifted Then 'kain

If ind = posopl Then

If Not square_on_threat(ind) Then Image7(piecenum).Top = Image1(ind).Top

Image7(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False

kingblackmoved = True

If gamemode = "Amateur" Then Call blackturnoff(ind)

Else

ProTaba = ind protime.Enabled = True

End If

Else

kukai = "Illegal Move!"

Timer6.Enabled = True

End If Else

kukai = "illegal Move!"

Timer6.Enabled = True End If

Else 'galaw lang

For i = 1 To 16 If Image1(ind).Top = Image7(i).Top And Image1(ind).Left =

Image7(i).Left Then

boolforpatong = True End If

Next i

If Not boolforpatong Then

If Not square_on_threat(ind) Then

If Not endtop And Not endbottom Then If (ind = position - 1 Or ind = position + 1 Or ind = position -

8 Or ind = position + 8 Or ind = position - 9 Or ind =

position + 9 Or ind = position - 7 Or ind = position + 7) Then

Page 96: PC-Based Electronic Chess Board Game

Appendix D D-47

Image7(piecenum).Top = Image1(ind).Top

Image7(piecenum).Left = Image1(ind).Left kingblackmoved = True

If gamemode = "Amateur" Then

Call blackturnoff(ind) Else

ProTaba = ind

protime.Enabled = True End If

Else

kukai = "Illegal Move!" Timer6.Enabled = True

End If

Else If endtop Then

If (ind = position - 8 Or ind = position + 8 Or ind = position

+ 9 Or ind = position - 7 Or ind = position + 1) Then Image7(piecenum).Top = Image1(ind).Top

Image7(piecenum).Left = Image1(ind).Left

kingblackmoved = True If gamemode = "Amateur" Then

Call blackturnoff(ind)

Else ProTaba = ind

protime.Enabled = True

End If Else

If Castable(ind) And Not blocked And Not checked And Not obstruction(ind) Then

Image7(piecenum).Top = Image1(ind).Top

Image7(piecenum).Left = Image1(ind).Left kingblackmoved = True

castling = True

reset_changed_tiles If gamemode = "Amateur" Then

lit_on (rookdes)

If ind > rookdes Then lit_on (57)

Else

lit_on (1) End If

End If

Else kukai = "Illegal Move!"

Timer6.Enabled = True

End If End If

Else

If endbottom Then

If (ind = position - 8 Or ind = position + 8 Or ind = position -

9 Or ind = position + 7 Or ind = position - 1) Then

Image7(piecenum).Top = Image1(ind).Top Image7(piecenum).Left = Image1(ind).Left

kingblackmoved = True

If gamemode = "Amateur" Then Call blackturnoff(ind)

Else

ProTaba = ind protime.Enabled = True

End If

Else kukai = "Illegal Move!"

Timer6.Enabled = True

End If End If

End If

End If Else

kukai = "Illegal Move!"

Timer6.Enabled = True

End If

End If End If

Case "R"

If opponentpiecelifted Then If ind = posopl Then

If checked Then

If naharangan_ba(ind) Then Image7(piecenum).Top = Image1(ind).Top

Image7(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False

If piecenum = 16 Then

rightrookblackmoved = True Else

leftrookblackmoved = True

End If If gamemode = "Amateur" Then

Call blackturnoff(ind)

Else ProTaba = ind

protime.Enabled = True

End If Else

kukai = "Illegal Move!"

Timer6.Enabled = True End If

Else If OpenCheckTilesCount > 0 Then

If OnOpenCheckTiles(ind) Then

Image7(piecenum).Top = Image1(ind).Top Image7(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False If piecenum = 16 Then

rightrookblackmoved = True

Else leftrookblackmoved = True

End If

If gamemode = "Amateur" Then Call blackturnoff(ind)

Else

ProTaba = ind protime.Enabled = True

End If

Else kukai = "Open Check!"

Timer6.Enabled = True

End If

Else

Image7(piecenum).Top = Image1(ind).Top

Image7(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False

If piecenum = 16 Then rightrookblackmoved = True

Else

leftrookblackmoved = True End If

If gamemode = "Amateur" Then

Call blackturnoff(ind) Else

ProTaba = ind

protime.Enabled = True End If

End If

End If Else

kukai = "Illegal Move!"

Timer6.Enabled = True

Page 97: PC-Based Electronic Chess Board Game

Appendix D D-48

End If

Else For i = 1 To 16

If Image1(ind).Top = Image7(i).Top And Image1(ind).Left =

Image7(i).Left Then boolforpatong = True

End If

Next i

If Not boolforpatong Then

If Not blocked Then If Image1(position).Top = Image1(ind).Top Or

Image1(position).Left = Image1(ind).Left Then

If checked Then If naharangan_ba(ind) Then

Image7(piecenum).Top = Image1(ind).Top

Image7(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False

If piecenum = 16 Then rightrookblackmoved = True

Else

leftrookblackmoved = True End If

If gamemode = "Amateur" Then

Call blackturnoff(ind) Else

ProTaba = ind protime.Enabled = True

End If

Else kukai = "Still on Check!"

Timer6.Enabled = True

End If Else

If OpenCheckTilesCount > 0 Then

If OnOpenCheckTiles(ind) Then Image7(piecenum).Top = Image1(ind).Top

Image7(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False

If piecenum = 16 Then

rightrookblackmoved = True Else

leftrookblackmoved = True

End If If gamemode = "Amateur" Then

Call blackturnoff(ind)

Else

ProTaba = ind

protime.Enabled = True

End If Else

kukai = "Open Check!"

Timer6.Enabled = True End If

Else

Image7(piecenum).Top = Image1(ind).Top Image7(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False If piecenum = 16 Then

rightrookblackmoved = True

Else leftrookblackmoved = True

End If

If gamemode = "Amateur" Then Call blackturnoff(ind)

Else

ProTaba = ind

protime.Enabled = True

End If End If

End If

Else kukai = "Illegal Move!"

Timer6.Enabled = True

End If Else

kukai = "Illegal Move!"

Timer6.Enabled = True End If

End If

End If Case "B"

If opponentpiecelifted Then

If ind = posopl Then If checked Then

If naharangan_ba(ind) Then

Image7(piecenum).Top = Image1(ind).Top Image7(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False If gamemode = "Amateur" Then

Call blackturnoff(ind)

Else ProTaba = ind

protime.Enabled = True End If

Else

kukai = "Still on Check!" Timer6.Enabled = True

End If

Else If OpenCheckTilesCount > 0 Then

If OnOpenCheckTiles(ind) Then

Image7(piecenum).Top = Image1(ind).Top Image7(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False If gamemode = "Amateur" Then

Call blackturnoff(ind)

Else ProTaba = ind

protime.Enabled = True

End If Else

kukai = "Open Check!"

Timer6.Enabled = True

End If

Else

Image7(piecenum).Top = Image1(ind).Top Image7(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False If gamemode = "Amateur" Then

Call blackturnoff(ind)

Else ProTaba = ind

protime.Enabled = True

End If End If

End If

Else kukai = "Illegal Move!"

Timer6.Enabled = True

End If Else

For i = 1 To 16

Page 98: PC-Based Electronic Chess Board Game

Appendix D D-49

If Image1(ind).Top = Image7(i).Top And Image1(ind).Left =

Image7(i).Left Then boolforpatong = True

End If

Next i

IMBcnt = 0

If Not boolforpatong Then If Not blocked Then

If Image1(position).Tag = Image1(ind).Tag Then

For j = 7 To 9 Step 2 For i = position - j To 1 Step -j

If ind = i Then

IMBcnt = IMBcnt + 1 If checked Then

If naharangan_ba(ind) Then

Image7(piecenum).Top = Image1(ind).Top Image7(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False If gamemode = "Amateur" Then

Call blackturnoff(ind)

Else ProTaba = ind

protime.Enabled = True

End If Else

kukai = "Still on Check!" Timer6.Enabled = True

End If

Else If OpenCheckTilesCount > 0 Then

If OnOpenCheckTiles(ind) Then

Image7(piecenum).Top = Image1(ind).Top Image7(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False If gamemode = "Amateur" Then

Call blackturnoff(ind)

Else ProTaba = ind

protime.Enabled = True

End If Else

kukai = "Open Check!"

Timer6.Enabled = True End If

Else

Image7(piecenum).Top = Image1(ind).Top

Image7(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False If gamemode = "Amateur" Then

Call blackturnoff(ind)

Else ProTaba = ind

protime.Enabled = True

End If End If

End If

End If Next i

For i = position + j To 64 Step j

If ind = i Then IMBcnt = IMBcnt + 1

If checked Then

If naharangan_ba(ind) Then Image7(piecenum).Top = Image1(ind).Top

Image7(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False

If gamemode = "Amateur" Then

Call blackturnoff(ind) Else

ProTaba = ind

protime.Enabled = True End If

Else

kukai = "Still on Check!" Timer6.Enabled = True

End If

Else If OpenCheckTilesCount > 0 Then

If OnOpenCheckTiles(ind) Then

Image7(piecenum).Top = Image1(ind).Top Image7(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False

If gamemode = "Amateur" Then Call blackturnoff(ind)

Else

ProTaba = ind protime.Enabled = True

End If

Else kukai = "Open Check!"

Timer6.Enabled = True

End If Else

Image7(piecenum).Top = Image1(ind).Top Image7(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False

If gamemode = "Amateur" Then Call blackturnoff(ind)

Else

ProTaba = ind protime.Enabled = True

End If

End If End If

End If

Next i Next j

If IMBcnt = 0 Then

kukai = "Illegal Move!" Timer6.Enabled = True

End If

Else kukai = "Illegal Move!"

Timer6.Enabled = True

End If

Else

kukai = "Illegal Move!"

Timer6.Enabled = True End If

End If

End If Case "Q"

If opponentpiecelifted Then

If ind = posopl Then If checked Then

If naharangan_ba(ind) Then

Image7(piecenum).Top = Image1(ind).Top Image7(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False If gamemode = "Amateur" Then

Call blackturnoff(ind)

Else ProTaba = ind

protime.Enabled = True

End If

Page 99: PC-Based Electronic Chess Board Game

Appendix D D-50

Else

kukai = "Still on Check!" Timer6.Enabled = True

End If

Else If OpenCheckTilesCount > 0 Then

If OnOpenCheckTiles(ind) Then

Image7(piecenum).Top = Image1(ind).Top Image7(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False If gamemode = "Amateur" Then

Call blackturnoff(ind)

Else ProTaba = ind

protime.Enabled = True

End If Else

kukai = "Open Check!"

Timer6.Enabled = True End If

Else

Image7(piecenum).Top = Image1(ind).Top Image7(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False If gamemode = "Amateur" Then

Call blackturnoff(ind) Else

ProTaba = ind

protime.Enabled = True End If

End If

End If Else

kukai = "Illegal Move!"

Timer6.Enabled = True End If

Else

For i = 1 To 16 If Image1(ind).Top = Image7(i).Top And Image1(ind).Left =

Image7(i).Left Then

boolforpatong = True End If

Next i

If Not boolforpatong Then

If Not blocked Then

If Image1(position).Top = Image1(ind).Top Or

Image1(position).Left = Image1(ind).Left Then

If checked Then

If naharangan_ba(ind) Then Image7(piecenum).Top = Image1(ind).Top

Image7(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False

If gamemode = "Amateur" Then

Call blackturnoff(ind) Else

ProTaba = ind

protime.Enabled = True End If

Else

kukai = "Still on Check!" Timer6.Enabled = True

End If

Else If OpenCheckTilesCount > 0 Then

If OnOpenCheckTiles(ind) Then

Image7(piecenum).Top = Image1(ind).Top

Image7(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False

If gamemode = "Amateur" Then

Call blackturnoff(ind) Else

ProTaba = ind

protime.Enabled = True End If

Else

kukai = "Open Check!" Timer6.Enabled = True

End If

Else Image7(piecenum).Top = Image1(ind).Top

Image7(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False

If gamemode = "Amateur" Then

Call blackturnoff(ind) Else

ProTaba = ind

protime.Enabled = True End If

End If

End If GoTo ExitPieceMoves

Else IMBcnt = 0

If Image1(position).Tag = Image1(ind).Tag Then

For j = 7 To 9 Step 2 For i = position - j To 1 Step -j

If ind = i Then

IMBcnt = IMBcnt + 1 If checked Then

If naharangan_ba(ind) Then

Image7(piecenum).Top = Image1(ind).Top Image7(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False If gamemode = "Amateur" Then

Call blackturnoff(ind)

Else ProTaba = ind

protime.Enabled = True

End If Else

kukai = "Still on Check!"

Timer6.Enabled = True

End If

Else

If OpenCheckTilesCount > 0 Then If OnOpenCheckTiles(ind) Then

Image7(piecenum).Top = Image1(ind).Top

Image7(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False

If gamemode = "Amateur" Then Call blackturnoff(ind)

Else

ProTaba = ind protime.Enabled = True

End If

Else kukai = "Open Check!"

Timer6.Enabled = True

End If Else

Image7(piecenum).Top = Image1(ind).Top

Image7(piecenum).Left = Image1(ind).Left

Page 100: PC-Based Electronic Chess Board Game

Appendix D D-51

opponentpiecelifted = False If gamemode = "Amateur" Then

Call blackturnoff(ind)

Else ProTaba = ind

protime.Enabled = True

End If End If

End If

End If Next i

For i = position + j To 64 Step j

If ind = i Then IMBcnt = IMBcnt + 1

If checked Then

If naharangan_ba(ind) Then Image7(piecenum).Top = Image1(ind).Top

Image7(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False

If gamemode = "Amateur" Then

Call blackturnoff(ind) Else

ProTaba = ind

protime.Enabled = True End If

Else kukai = "Still on Check!"

Timer6.Enabled = True

End If Else

If OpenCheckTilesCount > 0 Then

If OnOpenCheckTiles(ind) Then Image7(piecenum).Top = Image1(ind).Top

Image7(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False

If gamemode = "Amateur" Then

Call blackturnoff(ind) Else

ProTaba = ind

protime.Enabled = True End If

Else

kukai = "Open Check!" Timer6.Enabled = True

End If

Else

Image7(piecenum).Top = Image1(ind).Top

Image7(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False

If gamemode = "Amateur" Then

Call blackturnoff(ind) Else

ProTaba = ind

protime.Enabled = True End If

End If

End If End If

Next i

Next j If IMBcnt = 0 Then

kukai = "Illegal Move!"

Timer6.Enabled = True End If

Else

kukai = "Illegal Move!"

Timer6.Enabled = True

End If End If

Else

kukai = "Illegal Move!" Timer6.Enabled = True

End If

End If End If

End Select

End If

If picked Then

Select Case piece Case "P"

If opponentpiecelifted Then

If Not pawnpromote Then If (ind = position - 9 Or ind = position + 7) Then

If ind = posopl Then

If checked Then If naharangan_ba(ind) Then

Image6(piecenum).Left = Image1(ind).Left

Image6(piecenum).Top = Image1(ind).Top

opponentpiecelifted = False

whitepawnmoved(piecenum) = True If gamemode = "Amateur" Then

Call whiteturnoff(ind) Else

ProTaba = ind

protime.Enabled = True End If

Else

kukai = "Still on Check!" Timer6.Enabled = True

End If

Else Image6(piecenum).Left = Image1(ind).Left

Image6(piecenum).Top = Image1(ind).Top

opponentpiecelifted = False

whitepawnmoved(piecenum) = True

If gamemode = "Amateur" Then Call whiteturnoff(ind)

Else

ProTaba = ind protime.Enabled = True

End If

End If

Else

If (posopl = position - 8 Or posopl = position + 8) And

beyond(position) Then If enpassantpieceb(opl) Then

If posdes = ind Then

If checked Then If naharangan_ba(ind) Then

Image6(piecenum).Top = Image1(ind).Top

Image6(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False

If gamemode = "Amateur" Then Call whiteturnoff(ind)

Else

ProTaba = ind protime.Enabled = True

End If

Else kukai = "Still on Check!"

Timer6.Enabled = True

End If

Page 101: PC-Based Electronic Chess Board Game

Appendix D D-52

Else

Image6(piecenum).Top = Image1(ind).Top Image6(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False If gamemode = "Amateur" Then

Call whiteturnoff(ind)

Else ProTaba = ind

protime.Enabled = True

End If End If

Else

kukai = "Illegal Move!" Timer6.Enabled = True

End If

End If End If

End If

Else kukai = "Illegal Move!"

Timer6.Enabled = True

End If Else ' promoted

If position - 9 Or ind = position + 7 Then

If ind = posopl Then If checked Then

If naharangan_ba(ind) Then Image6(piecenum).Left = Image1(ind).Left

Image6(piecenum).Top = Image1(ind).Top

pawnpromotion (ind) opponentpiecelifted = False

whitepawnmoved(piecenum) = True

Else kukai = "Still on Check!"

Timer6.Enabled = True

End If Else

Image6(piecenum).Left = Image1(ind).Left

Image6(piecenum).Top = Image1(ind).Top pawnpromotion (ind)

opponentpiecelifted = False

whitepawnmoved(piecenum) = True End If

Else

If (posopl = position - 8 Or posopl = position + 8) And beyond(position) Then

If enpassantpieceb(opl) Then

If posdes = ind Then

If checked Then

If naharangan_ba(ind) Then

Image6(piecenum).Top = Image1(ind).Top Image6(piecenum).Left = Image1(ind).Left

pawnpromotion (ind)

opponentpiecelifted = False Else

kukai = "Still on Check!"

Timer6.Enabled = True End If

Else

Image6(piecenum).Top = Image1(ind).Top Image6(piecenum).Left = Image1(ind).Left

pawnpromotion (ind)

opponentpiecelifted = False End If

Else

kukai = "Illegal Move!" Timer6.Enabled = True

End If

End If

End If

End If Else

kukai = "Illegal Move!"

Timer6.Enabled = True End If

End If

Else If Not pawnpromoted Then

If ind = position - 1 Then

If checked Then If naharangan_ba(ind) Then

Image6(piecenum).Top = Image1(ind).Top

Image6(piecenum).Left = Image1(ind).Left

whitepawnmoved(piecenum) = True

If gamemode = "Amateur" Then Call whiteturnoff(ind)

Else

ProTaba = ind protime.Enabled = True

End If

GoTo ExitPieceMoves Else

kukai = "Still on Check!"

Timer6.Enabled = True End If

Else Image6(piecenum).Top = Image1(ind).Top

Image6(piecenum).Left = Image1(ind).Left

whitepawnmoved(piecenum) = True

If gamemode = "Amateur" Then

Call whiteturnoff(ind) Else

ProTaba = ind

protime.Enabled = True End If

GoTo ExitPieceMoves

End If Else

If ind = position - 2 Then

If Not whitepawnmoved(piecenum) Then If checked Then

If naharangan_ba(ind) Then

Image6(piecenum).Left = Image1(ind).Left Image6(piecenum).Top = Image1(ind).Top

whitepawnmoved(piecenum) = True

For i = 1 To 8

If ind + 8 < 65 Then

If Image1(ind + 8).Top = Image7(i).Top And Image1(ind + 8).Left = Image7(i).Left Then

enpassantpiecew(piecenum) = True

End If End If

If ind - 8 > 0 Then

If Image1(ind - 8).Top = Image7(i).Top And Image1(ind - 8).Left = Image7(i).Left Then

enpassantpiecew(piecenum) = True

End If End If

Next i

If gamemode = "Amateur" Then Call whiteturnoff(ind)

Else

ProTaba = ind protime.Enabled = True

End If

Else

Page 102: PC-Based Electronic Chess Board Game

Appendix D D-53

kukai = "Still on Check!"

Timer6.Enabled = True End If

Else

For j = 1 To 16 If (Image1(ind).Top = Image7(j).Top And Image1(ind).Left

= Image7(j).Left) Or (Image1(ind).Top = Image6(j).Top And

Image1(ind).Left = Image6(j).Left) Then boolforpatong = True

End If

Next j

If Not boolforpatong Then

Image6(piecenum).Left = Image1(ind).Left Image6(piecenum).Top = Image1(ind).Top

whitepawnmoved(piecenum) = True

For i = 1 To 8 If ind + 8 < 65 Then

If Image1(ind + 8).Top = Image7(i).Top And Image1(ind +

8).Left = Image7(i).Left Then enpassantpiecew(piecenum) = True

End If

End If If ind - 8 > 0 Then

If Image1(ind - 8).Top = Image7(i).Top And Image1(ind -

8).Left = Image7(i).Left Then enpassantpiecew(piecenum) = True

End If End If

Next i

If gamemode = "Amateur" Then Call whiteturnoff(ind)

Else

ProTaba = ind protime.Enabled = True

End If

End If End If

End If

Else kukai = "Illegal Move!"

Timer6.Enabled = True

End If End If

Else

If ind = position - 1 Then If checked Then

If naharangan_ba(ind) Then

Image6(piecenum).Left = Image1(ind).Left

Image6(piecenum).Top = Image1(ind).Top

Call pawnpromotion(ind) Else

kukai = "Still on Check!"

Timer6.Enabled = True End If

Else

Image6(piecenum).Left = Image1(ind).Left Image6(piecenum).Top = Image1(ind).Top

Call pawnpromotion(ind) End If

Else

kukai = "Illegal Move!" Timer6.Enabled = True

End If

End If End If

Case "N"

If opponentpiecelifted Then

If ind = posopl Then

If checked Then If naharangan_ba(ind) Then

Image6(piecenum).Top = Image1(ind).Top

Image6(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False

If gamemode = "Amateur" Then Call whiteturnoff(ind)

Else

ProTaba = ind protime.Enabled = True

End If

Else kukai = "Still on Check!"

Timer6.Enabled = True

End If Else

Image6(piecenum).Top = Image1(ind).Top

Image6(piecenum).Left = Image1(ind).Left opponentpiecelifted = False

If gamemode = "Amateur" Then

Call whiteturnoff(ind) Else

ProTaba = ind

protime.Enabled = True End If

End If Else

kukai = "Illegal Move!"

Timer6.Enabled = True End If

Else

For j = 1 To 16 If Image1(ind).Top = Image6(j).Top And Image1(ind).Left =

Image6(j).Left Then

boolforpatong = True End If

Next j

If Not boolforpatong Then

If Image1(position).Tag <> Image1(ind).Tag And (ind =

position - 6 Or ind = position - 10 Or ind = position - 15 Or ind = position - 17 Or ind = position + 6 Or ind = position +

10 Or ind = position + 15 Or ind = position + 17) Then

If checked Then If naharangan_ba(ind) Then

Image6(piecenum).Top = Image1(ind).Top

Image6(piecenum).Left = Image1(ind).Left

If gamemode = "Amateur" Then

Call whiteturnoff(ind) Else

ProTaba = ind

protime.Enabled = True End If

Else

kukai = "Still on Check!" Timer6.Enabled = True

End If

Else Image6(piecenum).Top = Image1(ind).Top

Image6(piecenum).Left = Image1(ind).Left

If gamemode = "Amateur" Then

Call whiteturnoff(ind)

Else ProTaba = ind

protime.Enabled = True

End If

Page 103: PC-Based Electronic Chess Board Game

Appendix D D-54

End If

Else kukai = "Illegal Move!"

Timer6.Enabled = True

End If End If

End If

Case "K" If opponentpiecelifted Then

If ind = posopl Then

If Not square_on_threat(ind) Then Image6(piecenum).Top = Image1(ind).Top

Image6(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False

kingwhitemoved = True

If gamemode = "Amateur" Then Call whiteturnoff(ind)

Else

ProTaba = ind protime.Enabled = True

End If

Else kukai = "Illegal Move!"

Timer6.Enabled = True

End If Else

kukai = "Illegal Move!" Timer6.Enabled = True

End If

Else For j = 1 To 16

If Image1(ind).Top = Image6(j).Top And Image1(ind).Left =

Image6(j).Left Then boolforpatong = True

End If

Next j

If Not boolforpatong Then

If Not square_on_threat(ind) Then If Not endtop And Not endbottom Then

If ind = position - 1 Or ind = position + 1 Or ind = position -

8 Or ind = position + 8 Or ind = position - 9 Or ind = position + 9 Or ind = position - 7 Or ind = position + 7 Then

Image6(piecenum).Top = Image1(ind).Top

Image6(piecenum).Left = Image1(ind).Left

kingwhitemoved = True

If gamemode = "Amateur" Then

Call whiteturnoff(ind)

Else

ProTaba = ind protime.Enabled = True

End If

Else kukai = "Illegal Move!"

Timer6.Enabled = True

End If Else

If endbottom Then

If ind = position - 8 Or ind = position + 8 Or ind = position - 9 Or ind = position + 7 Or ind = position - 1 Then

Image6(piecenum).Top = Image1(ind).Top

Image6(piecenum).Left = Image1(ind).Left

kingwhitemoved = True

If gamemode = "Amateur" Then Call whiteturnoff(ind)

Else

ProTaba = ind

protime.Enabled = True

End If Else

If Castable(ind) And (Not blocked) And (Not checked) And

(Not obstruction(ind)) And Not square_on_threat(ind) Then Image6(piecenum).Top = Image1(ind).Top

Image6(piecenum).Left = Image1(ind).Left

kingwhitemoved = True

castling = True

reset_changed_tiles If gamemode = "Amateur" Then

lit_on (rookdes)

If ind > rookdes Then lit_on (64)

Else

lit_on (8) End If

End If

Else kukai = "Illegal Move!"

Timer6.Enabled = True

End If End If

Else

If endtop And (ind = position - 8 Or ind = position + 8 Or ind = position + 9 Or ind = position - 7 Or ind = position + 1)

And Not square_on_threat(ind) Then Image6(piecenum).Top = Image1(ind).Top

Image6(piecenum).Left = Image1(ind).Left

kingwhitemoved = True

If gamemode = "Amateur" Then

Call whiteturnoff(ind) Else

ProTaba = ind

protime.Enabled = True End If

Else

kukai = "Illegal Move!" Timer6.Enabled = True

End If

End If End If

Else

kukai = "Illegal Move!" Timer6.Enabled = True

End If

End If

End If

Case "R"

If opponentpiecelifted Then If ind = posopl Then

If checked Then

If naharangan_ba(ind) Then Image6(piecenum).Top = Image1(ind).Top

Image6(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False If piecenum = 16 Then

rightrookwhitemoved = True

Else leftrookwhitemoved = True

End If

If gamemode = "Amateur" Then Call whiteturnoff(ind)

Else

ProTaba = ind protime.Enabled = True

End If

Else

Page 104: PC-Based Electronic Chess Board Game

Appendix D D-55

kukai = "Still on Check!"

Timer6.Enabled = True End If

Else

If OpenCheckTilesCount > 0 Then If OnOpenCheckTiles(ind) Then

Image6(piecenum).Top = Image1(ind).Top

Image6(piecenum).Left = Image1(ind).Left opponentpiecelifted = False

If piecenum = 16 Then

rightrookwhitemoved = True Else

leftrookwhitemoved = True

End If If gamemode = "Amateur" Then

Call whiteturnoff(ind)

Else ProTaba = ind

protime.Enabled = True

End If Else

kukai = "Open Check!"

Timer6.Enabled = True End If

Else

Image6(piecenum).Top = Image1(ind).Top Image6(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False If piecenum = 16 Then

rightrookwhitemoved = True

Else leftrookwhitemoved = True

End If

If gamemode = "Amateur" Then Call whiteturnoff(ind)

Else

ProTaba = ind protime.Enabled = True

End If

End If End If

Else

kukai = "Illegal Move!" Timer6.Enabled = True

End If

Else For j = 1 To 16

If Image1(ind).Top = Image6(j).Top And Image1(ind).Left =

Image6(j).Left Then

boolforpatong = True

End If

Next j

If Not boolforpatong Then

If Not blocked Then If Image1(position).Top = Image1(ind).Top Or

Image1(position).Left = Image1(ind).Left Then

If checked Then If naharangan_ba(ind) Then

Image6(piecenum).Top = Image1(ind).Top

Image6(piecenum).Left = Image1(ind).Left

If piecenum = 16 Then

rightrookwhitemoved = True Else

leftrookwhitemoved = True

End If If gamemode = "Amateur" Then

Call whiteturnoff(ind)

Else

ProTaba = ind

protime.Enabled = True End If

Else

kukai = "Still on Check!" Timer6.Enabled = True

End If

Else If OpenCheckTilesCount > 0 Then

If OnOpenCheckTiles(ind) Then

Image6(piecenum).Top = Image1(ind).Top Image6(piecenum).Left = Image1(ind).Left

If piecenum = 16 Then

rightrookwhitemoved = True Else

leftrookwhitemoved = True

End If If gamemode = "Amateur" Then

Call whiteturnoff(ind)

Else ProTaba = ind

protime.Enabled = True

End If Else

kukai = "Still on Check!"

Timer6.Enabled = True End If

Else Image6(piecenum).Top = Image1(ind).Top

Image6(piecenum).Left = Image1(ind).Left

If piecenum = 16 Then rightrookwhitemoved = True

Else

leftrookwhitemoved = True End If

If gamemode = "Amateur" Then

Call whiteturnoff(ind) Else

ProTaba = ind

protime.Enabled = True End If

End If

End If Else

kukai = "Illegal Move!"

Timer6.Enabled = True End If

Else

kukai = "Illegal Move!"

Timer6.Enabled = True

End If

End If End If

Case "B"

If opponentpiecelifted Then If ind = posopl Then

If checked Then

If naharangan_ba(ind) Then Image6(piecenum).Top = Image1(ind).Top

Image6(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False If gamemode = "Amateur" Then

Call whiteturnoff(ind)

Else ProTaba = ind

protime.Enabled = True

End If Else

kukai = "Still on Check!"

Timer6.Enabled = True

Page 105: PC-Based Electronic Chess Board Game

Appendix D D-56

End If

Else If OpenCheckTilesCount > 0 Then

If OnOpenCheckTiles(ind) Then

Image6(piecenum).Top = Image1(ind).Top Image6(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False

If gamemode = "Amateur" Then Call whiteturnoff(ind)

Else

ProTaba = ind protime.Enabled = True

End If

Else kukai = "Open Check!"

Timer6.Enabled = True

End If Else

Image6(piecenum).Top = Image1(ind).Top

Image6(piecenum).Left = Image1(ind).Left opponentpiecelifted = False

If gamemode = "Amateur" Then

Call whiteturnoff(ind) Else

ProTaba = ind

protime.Enabled = True End If

End If End If

Else

kukai = "Illegal Move!" Timer6.Enabled = True

End If

Else For j = 1 To 16

If Image1(ind).Top = Image6(j).Top And Image1(ind).Left =

Image6(j).Left Then boolforpatong = True

End If

Next j IMBcnt = 0

If Not boolforpatong Then

If Not blocked Then If Image1(position).Tag = Image1(ind).Tag Then

For j = 7 To 9 Step 2

For i = position - j To 1 Step -j If ind = i Then

IMBcnt = IMBcnt + 1

If checked Then

If naharangan_ba(ind) Then

Image6(piecenum).Top = Image1(ind).Top

Image6(piecenum).Left = Image1(ind).Left If gamemode = "Amateur" Then

Call whiteturnoff(ind)

Else ProTaba = ind

protime.Enabled = True

End If Else

kukai = "Still on Check!"

Timer6.Enabled = True End If

Else

If OpenCheckTilesCount > 0 Then If OnOpenCheckTiles(ind) Then

Image6(piecenum).Top = Image1(ind).Top

Image6(piecenum).Left = Image1(ind).Left If gamemode = "Amateur" Then

Call whiteturnoff(ind)

Else

ProTaba = ind

protime.Enabled = True End If

Else

kukai = "Open Check!" Timer6.Enabled = True

End If

Else Image6(piecenum).Top = Image1(ind).Top

Image6(piecenum).Left = Image1(ind).Left

If gamemode = "Amateur" Then Call whiteturnoff(ind)

Else

ProTaba = ind protime.Enabled = True

End If

End If End If

End If

Next i For i = position + j To 64 Step j

If ind = i Then

IMBcnt = IMBcnt + 1 If checked Then

If naharangan_ba(ind) Then

Image6(piecenum).Top = Image1(ind).Top Image6(piecenum).Left = Image1(ind).Left

If gamemode = "Amateur" Then Call whiteturnoff(ind)

Else

ProTaba = ind protime.Enabled = True

End If

Else kukai = "Still on Check!"

Timer6.Enabled = True

End If Else

If OpenCheckTilesCount > 0 Then

If OnOpenCheckTiles(ind) Then Image6(piecenum).Top = Image1(ind).Top

Image6(piecenum).Left = Image1(ind).Left

If gamemode = "Amateur" Then Call whiteturnoff(ind)

Else

ProTaba = ind protime.Enabled = True

End If

Else

kukai = "Still on Check!"

Timer6.Enabled = True

End If Else

Image6(piecenum).Top = Image1(ind).Top

Image6(piecenum).Left = Image1(ind).Left

If gamemode = "Amateur" Then

Call whiteturnoff(ind) Else

ProTaba = ind

protime.Enabled = True End If

End If

End If End If

Next i

Next j If IMBcnt = 0 Then

kukai = "Illegal Move!"

Timer6.Enabled = True

Page 106: PC-Based Electronic Chess Board Game

Appendix D D-57

End If

Else kukai = "Illegal Move!"

Timer6.Enabled = True

End If Else

kukai = "Illegal Move!"

Timer6.Enabled = True End If

End If

End If Case "Q"

If opponentpiecelifted Then

If ind = posopl Then If checked Then

If naharangan_ba(ind) Then

Image6(piecenum).Top = Image1(ind).Top Image6(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False

If gamemode = "Amateur" Then Call whiteturnoff(ind)

Else

ProTaba = ind protime.Enabled = True

End If

Else kukai = "Still on Check!"

Timer6.Enabled = True End If

Else

If OpenCheckTilesCount > 0 Then If OnOpenCheckTiles(ind) Then

Image6(piecenum).Top = Image1(ind).Top

Image6(piecenum).Left = Image1(ind).Left opponentpiecelifted = False

If gamemode = "Amateur" Then

Call whiteturnoff(ind) Else

ProTaba = ind

protime.Enabled = True End If

Else

kukai = "Still on Check!" Timer6.Enabled = True

End If

Else Image6(piecenum).Top = Image1(ind).Top

Image6(piecenum).Left = Image1(ind).Left

opponentpiecelifted = False

If gamemode = "Amateur" Then

Call whiteturnoff(ind)

Else ProTaba = ind

protime.Enabled = True

End If End If

End If

Else kukai = "Illegal Move!"

Timer6.Enabled = True

End If Else

For j = 1 To 16

If Image1(ind).Top = Image6(j).Top And Image1(ind).Left = Image6(j).Left Then

boolforpatong = True

End If Next j

If Not boolforpatong Then

If Not blocked Then

If Image1(position).Top = Image1(ind).Top Or Image1(position).Left = Image1(ind).Left Then

If checked Then

If naharangan_ba(ind) Then Image6(piecenum).Top = Image1(ind).Top

Image6(piecenum).Left = Image1(ind).Left

If gamemode = "Amateur" Then Call whiteturnoff(ind)

Else

ProTaba = ind protime.Enabled = True

End If

Else kukai = "Still on Check!"

Timer6.Enabled = True

End If Else

If OpenCheckTilesCount > 0 Then

If OnOpenCheckTiles(ind) Then Image6(piecenum).Top = Image1(ind).Top

Image6(piecenum).Left = Image1(ind).Left

If gamemode = "Amateur" Then Call whiteturnoff(ind)

Else

ProTaba = ind protime.Enabled = True

End If Else

kukai = "Open Check!"

Timer6.Enabled = True End If

Else

Image6(piecenum).Top = Image1(ind).Top Image6(piecenum).Left = Image1(ind).Left

If gamemode = "Amateur" Then Call whiteturnoff(ind)

Else

ProTaba = ind protime.Enabled = True

End If

End If End If

GoTo ExitPieceMoves

Else IMBcnt = 0

If Image1(position).Tag = Image1(ind).Tag Then

For j = 7 To 9 Step 2

For i = position - j To 1 Step -j

If ind = i Then

IMBcnt = IMBcnt + 1 If checked Then

If naharangan_ba(ind) Then

Image6(piecenum).Top = Image1(ind).Top Image6(piecenum).Left = Image1(ind).Left

If gamemode = "Amateur" Then

Call whiteturnoff(ind) Else

ProTaba = ind

protime.Enabled = True End If

Else

kukai = "Still on Check!" Timer6.Enabled = True

End If

Else If OpenCheckTilesCount > 0 Then

If OnOpenCheckTiles(ind) Then

Image6(piecenum).Top = Image1(ind).Top

Page 107: PC-Based Electronic Chess Board Game

Appendix D D-58

Image6(piecenum).Left = Image1(ind).Left

If gamemode = "Amateur" Then Call whiteturnoff(ind)

Else

ProTaba = ind protime.Enabled = True

End If

Else kukai = "Open Check!"

Timer6.Enabled = True

End If Else

Image6(piecenum).Top = Image1(ind).Top

Image6(piecenum).Left = Image1(ind).Left If gamemode = "Amateur" Then

Call whiteturnoff(ind)

Else ProTaba = ind

protime.Enabled = True

End If End If

End If

End If Next i

For i = position + j To 64 Step j

If ind = i Then IMBcnt = IMBcnt + 1

If checked Then If naharangan_ba(ind) Then

Image6(piecenum).Top = Image1(ind).Top

Image6(piecenum).Left = Image1(ind).Left If gamemode = "Amateur" Then

Call whiteturnoff(ind)

Else ProTaba = ind

protime.Enabled = True

End If Else

kukai = "Still on Check!"

Timer6.Enabled = True End If

Else

If OpenCheckTilesCount > 0 Then If OnOpenCheckTiles(ind) Then

Image6(piecenum).Top = Image1(ind).Top

Image6(piecenum).Left = Image1(ind).Left If gamemode = "Amateur" Then

Call whiteturnoff(ind)

Else

ProTaba = ind

protime.Enabled = True

End If Else

kukai = "Open Check!"

Timer6.Enabled = True End If

Else

Image6(piecenum).Top = Image1(ind).Top Image6(piecenum).Left = Image1(ind).Left

If gamemode = "Amateur" Then

Call whiteturnoff(ind) Else

ProTaba = ind

protime.Enabled = True End If

End If

End If End If

Next i

Next j

If IMBcnt = 0 Then

kukai = "Illegal Move!" Timer6.Enabled = True

End If

Else kukai = "Illegal Move!"

Timer6.Enabled = True

End If End If

Else

kukai = "Illegal Move!" Timer6.Enabled = True

End If

End If End If

End Select

End If boolforpatong = False

ExitPieceMoves:

End Function

Private Function blockway(ind As Integer) As Boolean

Dim kolum As Integer, kurow As Integer, loops As Integer kolum = what_column(position)

kurow = what_row(position)

blockway = False counter = 0

tagcounter = 0 If whiteturn Then

Select Case piece

'******** '* PAWN *

'********

Case "P" For i = 1 To 16

If (Image1(position - 1).Top = Image6(i).Top And

Image1(position - 1).Left = Image6(i).Left) Or (Image1(position - 1).Top = Image7(i).Top And

Image1(position - 1).Left = Image7(i).Left) Then

blockway = True End If

Next i

'******** '* ROOK *

'********

Case "R" If Not picked Then

If position - 1 > 0 Then

If Image1(position).Left = Image1(position - 1).Left Then

tagcounter = tagcounter + 1

For j = 1 To 16

If Image6(j).Top = Image1(position - 1).Top And Image6(j).Left = Image1(position - 1).Left Then

counter = counter + 1

End If Next j

End If

End If If position + 1 < 65 Then

If Image1(position).Left = Image1(position + 1).Left Then

tagcounter = tagcounter + 1 For j = 1 To 16

If Image6(j).Top = Image1(position + 1).Top And

Image6(j).Left = Image1(position + 1).Left Then counter = counter + 1

End If

Next j End If

End If

If position - 8 > 0 Then

Page 108: PC-Based Electronic Chess Board Game

Appendix D D-59

If Image1(position).Top = Image1(position - 8).Top Then

tagcounter = tagcounter + 1 For j = 1 To 16

If Image6(j).Top = Image1(position - 8).Top And

Image6(j).Left = Image1(position - 8).Left Then counter = counter + 1

End If

Next j End If

End If

If position + 8 < 65 Then If Image1(position).Top = Image1(position + 8).Top Then

tagcounter = tagcounter + 1

For j = 1 To 16 If Image6(j).Top = Image1(position + 8).Top And

Image6(j).Left = Image1(position + 8).Left Then

counter = counter + 1 End If

Next j

End If End If

If tagcounter = counter Then

blockway = True End If

Else

If Image1(ind).Left = Image1(position).Left Then If ind < position Then

For i = 1 To 16 For j = ind + 1 To position - 1

If (Image6(i).Top = Image1(j).Top And Image6(i).Left =

Image1(j).Left) Or (Image7(i).Top = Image1(j).Top And Image7(i).Left = Image1(j).Left) Then

blockway = True

End If Next j

Next i

End If If ind > position + 1 Then

For i = 1 To 16

For j = ind - 1 To position + 1 Step -1 If (Image6(i).Top = Image1(j).Top And Image6(i).Left =

Image1(j).Left) Or (Image7(i).Top = Image1(j).Top And

Image7(i).Left = Image1(j).Left) Then blockway = True

End If

Next j Next i

End If

End If

If Image1(ind).Top = Image1(position).Top Then

If ind < position Then

For i = 1 To 16 For j = ind + 8 To position - 8 Step 8

If (Image6(i).Top = Image1(j).Top And Image6(i).Left =

Image1(j).Left) Or (Image7(i).Top = Image1(j).Top And Image7(i).Left = Image1(j).Left) Then

blockway = True

End If Next j

Next i

End If If ind > position Then

For i = 1 To 16

For j = ind - 8 To position + 8 Step -8 If (Image6(i).Top = Image1(j).Top And Image6(i).Left =

Image1(j).Left) Or (Image7(i).Top = Image1(j).Top And

Image7(i).Left = Image1(j).Left) Then blockway = True

End If

Next j

Next i

End If End If

End If

'********* '* HORSE *

'*********

Case "N" For j = 6 To 10 Step 4

If position - j > 0 Then

If Image1(position).Tag <> Image1(position - j).Tag Then tagcounter = tagcounter + 1

For i = 1 To 16

If Image6(i).Top = Image1(position - j).Top And Image6(i).Left = Image1(position - j).Left Then

counter = counter + 1

End If Next i

End If

End If Next j

For j = 15 To 17 Step 2

If position - j > 0 Then If Image1(position).Tag <> Image1(position - j).Tag Then

tagcounter = tagcounter + 1

For i = 1 To 16 If Image6(i).Top = Image1(position - j).Top And

Image6(i).Left = Image1(position - j).Left Then counter = counter + 1

End If

Next i End If

End If

Next j For j = 6 To 10 Step 4

If position + j < 65 Then

If Image1(position).Tag <> Image1(position + j).Tag Then tagcounter = tagcounter + 1

For i = 1 To 16

If Image6(i).Top = Image1(position + j).Top And Image6(i).Left = Image1(position + j).Left Then

counter = counter + 1

End If Next i

End If

End If Next j

For j = 15 To 17 Step 2

If position + j < 65 Then

If Image1(position).Tag <> Image1(position + j).Tag Then

tagcounter = tagcounter + 1

For i = 1 To 16 If Image6(i).Top = Image1(position + j).Top And

Image6(i).Left = Image1(position + j).Left Then

counter = counter + 1 End If

Next i

End If End If

Next j

If tagcounter = counter Then blockway = True

End If

'**************** '* QUEEN & KING *

'****************

Case "Q", "K" If Not picked Then

If position - 1 > 0 Then

If Image1(position).Left = Image1(position - 1).Left Then

Page 109: PC-Based Electronic Chess Board Game

Appendix D D-60

tagcounter = tagcounter + 1

For j = 1 To 16 If Image6(j).Top = Image1(position - 1).Top And

Image6(j).Left = Image1(position - 1).Left Then

counter = counter + 1 End If

Next j

End If End If

If position + 1 < 65 Then

If Image1(position).Left = Image1(position + 1).Left Then tagcounter = tagcounter + 1

For j = 1 To 16

If Image6(j).Top = Image1(position + 1).Top And Image6(j).Left = Image1(position + 1).Left Then

counter = counter + 1

End If Next j

End If

End If If position - 8 > 0 Then

If Image1(position).Top = Image1(position - 8).Top Then

tagcounter = tagcounter + 1 For j = 1 To 16

If Image6(j).Top = Image1(position - 8).Top And

Image6(j).Left = Image1(position - 8).Left Then counter = counter + 1

End If Next j

End If

End If If position + 8 < 65 Then

If Image1(position).Top = Image1(position + 8).Top Then

tagcounter = tagcounter + 1 For j = 1 To 16

If Image6(j).Top = Image1(position + 8).Top And

Image6(j).Left = Image1(position + 8).Left Then counter = counter + 1

End If

Next j End If

End If

If position - 9 > 0 Then If Image1(position).Tag = Image1(position - 9).Tag Then

tagcounter = tagcounter + 1

For j = 1 To 16 If Image6(j).Top = Image1(position - 9).Top And

Image6(j).Left = Image1(position - 9).Left Then

counter = counter + 1

End If

Next j

End If End If

If position - 7 > 0 Then

If Image1(position).Tag = Image1(position - 7).Tag Then tagcounter = tagcounter + 1

For j = 1 To 16

If Image6(j).Top = Image1(position - 7).Top And Image6(j).Left = Image1(position - 7).Left Then

counter = counter + 1

End If Next j

End If

End If If position + 9 < 65 Then

If Image1(position).Tag = Image1(position + 9).Tag Then

tagcounter = tagcounter + 1 For j = 1 To 16

If Image6(j).Top = Image1(position + 9).Top And

Image6(j).Left = Image1(position + 9).Left Then

counter = counter + 1

End If Next j

End If

End If If position + 7 < 65 Then

If Image1(position).Tag = Image1(position + 7).Tag Then

tagcounter = tagcounter + 1 For j = 1 To 16

If Image6(j).Top = Image1(position + 7).Top And

Image6(j).Left = Image1(position + 7).Left Then counter = counter + 1

End If

Next j End If

End If

If tagcounter = counter Then blockway = True

End If

Else If piece = "K" Then

If ind = 56 Then

For i = 1 To 16 If (Image6(i).Top = Image1(48).Top And Image6(i).Left =

Image1(48).Left) Or (Image7(i).Top = Image1(48).Top And

Image7(i).Left = Image1(48).Left) Then blockway = True

End If Next i

End If

If ind = 24 Then For i = 1 To 16

For j = 16 To 32 Step 16

If (Image6(i).Top = Image1(j).Top And Image6(i).Left = Image1(j).Left) Or (Image7(i).Top = Image1(j).Top And

Image7(i).Left = Image1(j).Left) Then

blockway = True End If

Next j

Next i End If

End If

If piece = "Q" Then If Image1(ind).Left = Image1(position).Left Then

If ind < position Then

For i = 1 To 16 For j = ind + 1 To position - 1

If (Image6(i).Top = Image1(j).Top And Image6(i).Left =

Image1(j).Left) Or (Image7(i).Top = Image1(j).Top And

Image7(i).Left = Image1(j).Left) Then

blockway = True

End If Next j

Next i

End If If ind > position + 1 Then

For i = 1 To 16

For j = ind - 1 To position + 1 Step -1 If (Image6(i).Top = Image1(j).Top And Image6(i).Left =

Image1(j).Left) Or (Image7(i).Top = Image1(j).Top And

Image7(i).Left = Image1(j).Left) Then blockway = True

End If

Next j Next i

End If

Else If Image1(ind).Top = Image1(position).Top Then

If ind < position Then

For i = 1 To 16

Page 110: PC-Based Electronic Chess Board Game

Appendix D D-61

For j = ind + 8 To position - 8 Step 8

If (Image6(i).Top = Image1(j).Top And Image6(i).Left = Image1(j).Left) Or (Image7(i).Top = Image1(j).Top And

Image7(i).Left = Image1(j).Left) Then

blockway = True End If

Next j

Next i End If

If ind > position Then

For i = 1 To 16 For j = ind - 8 To position + 8 Step -8

If (Image6(i).Top = Image1(j).Top And Image6(i).Left =

Image1(j).Left) Or (Image7(i).Top = Image1(j).Top And Image7(i).Left = Image1(j).Left) Then

blockway = True

End If Next j

Next i

End If Else

If Image1(ind).Tag = Image1(position).Tag Then

If ind < position Then For i = 1 To 16

For k = position To 1 Step -9

If ind = k Then For j = ind + 9 To position - 9 Step 9

If (Image6(i).Top = Image1(j).Top And Image6(i).Left = Image1(j).Left) Or (Image7(i).Top = Image1(j).Top And

Image7(i).Left = Image1(j).Left) Then

blockway = True End If

Next j

End If Next k

For k = position To 1 Step -7

If ind = k Then For j = ind + 7 To position - 7 Step 7

If (Image6(i).Top = Image1(j).Top And Image6(i).Left =

Image1(j).Left) Or (Image7(i).Top = Image1(j).Top And Image7(i).Left = Image1(j).Left) Then

blockway = True

End If Next j

End If

Next k Next i

End If

If ind > position Then

For i = 1 To 16

For k = position To 64 Step 9

If ind = k Then For j = ind - 9 To position + 9 Step -9

If (Image6(i).Top = Image1(j).Top And Image6(i).Left =

Image1(j).Left) Or (Image7(i).Top = Image1(j).Top And Image7(i).Left = Image1(j).Left) Then

blockway = True

End If Next j

End If

Next k For k = position To 64 Step 7

If ind = k Then

For j = ind - 7 To position + 7 Step -7 If (Image6(i).Top = Image1(j).Top And Image6(i).Left =

Image1(j).Left) Or (Image7(i).Top = Image1(j).Top And

Image7(i).Left = Image1(j).Left) Then blockway = True

End If

Next j

End If

Next k Next i

End If

End If End If

End If

End If End If

'**********

'* BISHOP * '**********

Case "B"

If Not picked Then If position - 9 > 0 Then

If Image1(position).Tag = Image1(position - 9).Tag Then

tagcounter = tagcounter + 1 For j = 1 To 16

If Image6(j).Top = Image1(position - 9).Top And

Image6(j).Left = Image1(position - 9).Left Then counter = counter + 1

End If

Next j End If

End If

If position - 7 > 0 Then If Image1(position).Tag = Image1(position - 7).Tag Then

tagcounter = tagcounter + 1 For j = 1 To 16

If Image6(j).Top = Image1(position - 7).Top And

Image6(j).Left = Image1(position - 7).Left Then counter = counter + 1

End If

Next j End If

End If

If position + 9 < 65 Then If Image1(position).Tag = Image1(position + 9).Tag Then

tagcounter = tagcounter + 1

For j = 1 To 16 If Image6(j).Top = Image1(position + 9).Top And

Image6(j).Left = Image1(position + 9).Left Then

counter = counter + 1 End If

Next j

End If End If

If position + 7 < 65 Then

If Image1(position).Tag = Image1(position + 7).Tag Then

tagcounter = tagcounter + 1

For j = 1 To 16

If Image6(j).Top = Image1(position + 7).Top And Image6(j).Left = Image1(position + 7).Left Then

counter = counter + 1

End If Next j

End If

End If If tagcounter = counter Then

blockway = True

End If Else

If Image1(ind).Tag = Image1(position).Tag Then

If ind < position Then For i = 1 To 16

For k = position To 1 Step -9

If ind = k Then For j = ind + 9 To position - 9 Step 9

Page 111: PC-Based Electronic Chess Board Game

Appendix D D-62

If (Image6(i).Top = Image1(j).Top And Image6(i).Left =

Image1(j).Left) Or (Image7(i).Top = Image1(j).Top And Image7(i).Left = Image1(j).Left) Then

blockway = True

End If Next j

End If

Next k For k = position To 1 Step -7

If ind = k Then

For j = ind + 7 To position - 7 Step 7 If (Image6(i).Top = Image1(j).Top And Image6(i).Left =

Image1(j).Left) Or (Image7(i).Top = Image1(j).Top And

Image7(i).Left = Image1(j).Left) Then blockway = True

End If

Next j End If

Next k

Next i End If

If ind > position Then

For i = 1 To 16 For k = position To 64 Step 9

If ind = k Then

For j = ind - 9 To position + 9 Step -9 If (Image6(i).Top = Image1(j).Top And Image6(i).Left =

Image1(j).Left) Or (Image7(i).Top = Image1(j).Top And Image7(i).Left = Image1(j).Left) Then

blockway = True

End If Next j

End If

Next k For k = position To 64 Step 7

If ind = k Then

For j = ind - 7 To position + 7 Step -7 If (Image6(i).Top = Image1(j).Top And Image6(i).Left =

Image1(j).Left) Or (Image7(i).Top = Image1(j).Top And

Image7(i).Left = Image1(j).Left) Then blockway = True

End If

Next j End If

Next k

Next i End If

End If

End If

End Select

End If

If blackturn Then

Select Case piece

'****** '*PAWN*

'******

Case "P" For i = 1 To 16

If (Image1(position + 1).Top = Image6(i).Top And

Image1(position + 1).Left = Image6(i).Left) Or (Image1(position + 1).Top = Image7(i).Top And

Image1(position + 1).Left = Image7(i).Left) Then

blockway = True End If

Next i

'******** '* ROOK *

'********

Case "R"

If Not bpicked Then

If position - 1 > 0 Then If Image1(position).Left = Image1(position - 1).Left Then

tagcounter = tagcounter + 1

For j = 1 To 16 If Image7(j).Top = Image1(position - 1).Top And

Image7(j).Left = Image1(position - 1).Left Then

counter = counter + 1 End If

Next j

End If End If

If position + 1 < 65 Then

If Image1(position).Left = Image1(position + 1).Left Then tagcounter = tagcounter + 1

For j = 1 To 16

If Image7(j).Top = Image1(position + 1).Top And Image7(j).Left = Image1(position + 1).Left Then

counter = counter + 1

End If Next j

End If

End If If position - 8 > 0 Then

If Image1(position).Top = Image1(position - 8).Top Then

tagcounter = tagcounter + 1 For j = 1 To 16

If Image7(j).Top = Image1(position - 8).Top And Image7(j).Left = Image1(position - 8).Left Then

counter = counter + 1

End If Next j

End If

End If If position + 8 < 65 Then

If Image1(position).Top = Image1(position + 8).Top Then

tagcounter = tagcounter + 1 For j = 1 To 16

If Image7(j).Top = Image1(position + 8).Top And

Image7(j).Left = Image1(position + 8).Left Then counter = counter + 1

End If

Next j End If

End If

If tagcounter = counter Then blockway = True

End If

Else

If Image1(ind).Left = Image1(position).Left Then

If ind < position Then

For i = 1 To 16 For j = ind + 1 To position - 1

If (Image6(i).Top = Image1(j).Top And Image6(i).Left =

Image1(j).Left) Or (Image7(i).Top = Image1(j).Top And Image7(i).Left = Image1(j).Left) Then

blockway = True

End If Next j

Next i

End If If ind > position + 1 Then

For i = 1 To 16

For j = ind - 1 To position + 1 Step -1 If (Image6(i).Top = Image1(j).Top And Image6(i).Left =

Image1(j).Left) Or (Image7(i).Top = Image1(j).Top And

Image7(i).Left = Image1(j).Left) Then blockway = True

End If

Next j

Page 112: PC-Based Electronic Chess Board Game

Appendix D D-63

Next i

End If End If

If Image1(ind).Top = Image1(position).Top Then

If ind < position Then For i = 1 To 16

For j = ind + 8 To position - 8 Step 8

If (Image6(i).Top = Image1(j).Top And Image6(i).Left = Image1(j).Left) Or (Image7(i).Top = Image1(j).Top And

Image7(i).Left = Image1(j).Left) Then

blockway = True End If

Next j

Next i End If

If ind > position Then

For i = 1 To 16 For j = ind - 8 To position + 8 Step -8

If (Image6(i).Top = Image1(j).Top And Image6(i).Left =

Image1(j).Left) Or (Image7(i).Top = Image1(j).Top And Image7(i).Left = Image1(j).Left) Then

blockway = True

End If Next j

Next i

End If End If

End If '*********

'* HORSE *

'********* Case "N"

For j = 6 To 10 Step 4

If position - j > 0 Then If Image1(position).Tag <> Image1(position - j).Tag Then

tagcounter = tagcounter + 1

For i = 1 To 16 If Image7(i).Top = Image1(position - j).Top And

Image7(i).Left = Image1(position - j).Left Then

counter = counter + 1 End If

Next i

End If End If

Next j

For j = 15 To 17 Step 2 If position - j > 0 Then

If Image1(position).Tag <> Image1(position - j).Tag Then

tagcounter = tagcounter + 1

For i = 1 To 16

If Image7(i).Top = Image1(position - j).Top And

Image7(i).Left = Image1(position - j).Left Then counter = counter + 1

End If

Next i End If

End If

Next j For j = 6 To 10 Step 4

If position + j < 65 Then

If Image1(position).Tag <> Image1(position + j).Tag Then tagcounter = tagcounter + 1

For i = 1 To 16

If Image7(i).Top = Image1(position + j).Top And Image7(i).Left = Image1(position + j).Left Then

counter = counter + 1

End If Next i

End If

End If

Next j

For j = 15 To 17 Step 2 If position + j < 65 Then

If Image1(position).Tag <> Image1(position + j).Tag Then

tagcounter = tagcounter + 1 For i = 1 To 16

If Image7(i).Top = Image1(position + j).Top And

Image7(i).Left = Image1(position + j).Left Then counter = counter + 1

End If

Next i End If

End If

Next j If tagcounter = counter Then

blockway = True

End If '****************

'* QUEEN & KING *

'**************** Case "K", "Q"

If Not bpicked Then

If position - 1 > 0 Then If Image1(position).Left = Image1(position - 1).Left Then

tagcounter = tagcounter + 1

For j = 1 To 16 If Image7(j).Top = Image1(position - 1).Top And

Image7(j).Left = Image1(position - 1).Left Then counter = counter + 1

End If

Next j End If

End If

If position + 1 < 65 Then If Image1(position).Left = Image1(position + 1).Left Then

tagcounter = tagcounter + 1

For j = 1 To 16 If Image7(j).Top = Image1(position + 1).Top And

Image7(j).Left = Image1(position + 1).Left Then

counter = counter + 1 End If

Next j

End If End If

If position - 8 > 0 Then

If Image1(position).Top = Image1(position - 8).Top Then tagcounter = tagcounter + 1

For j = 1 To 16

If Image7(j).Top = Image1(position - 8).Top And

Image7(j).Left = Image1(position - 8).Left Then

counter = counter + 1

End If Next j

End If

End If If position + 8 < 65 Then

If Image1(position).Top = Image1(position + 8).Top Then

tagcounter = tagcounter + 1 For j = 1 To 16

If Image7(j).Top = Image1(position + 8).Top And

Image7(j).Left = Image1(position + 8).Left Then counter = counter + 1

End If

Next j End If

End If

If position - 9 > 0 Then If Image1(position).Tag = Image1(position - 9).Tag Then

tagcounter = tagcounter + 1

For j = 1 To 16

Page 113: PC-Based Electronic Chess Board Game

Appendix D D-64

If Image7(j).Top = Image1(position - 9).Top And

Image7(j).Left = Image1(position - 9).Left Then counter = counter + 1

End If

Next j End If

End If

If position - 7 > 0 Then If Image1(position).Tag = Image1(position - 7).Tag Then

tagcounter = tagcounter + 1

For j = 1 To 16 If Image7(j).Top = Image1(position - 7).Top And

Image7(j).Left = Image1(position - 7).Left Then

counter = counter + 1 End If

Next j

End If End If

If position + 9 < 65 Then

If Image1(position).Tag = Image1(position + 9).Tag Then tagcounter = tagcounter + 1

For j = 1 To 16

If Image7(j).Top = Image1(position + 9).Top And Image7(j).Left = Image1(position + 9).Left Then

counter = counter + 1

End If Next j

End If End If

If position + 7 < 65 Then

If Image1(position).Tag = Image1(position + 7).Tag Then tagcounter = tagcounter + 1

For j = 1 To 16

If Image7(j).Top = Image1(position + 7).Top And Image7(j).Left = Image1(position + 7).Left Then

counter = counter + 1

End If Next j

End If

End If If tagcounter = counter Then

blockway = True

End If Else

If piece = "K" Then

If ind = 49 Then For i = 1 To 16

If (Image6(i).Top = Image1(41).Top And Image6(i).Left =

Image1(41).Left) Or (Image7(i).Top = Image1(41).Top And

Image7(i).Left = Image1(41).Left) Then

blockway = True

End If Next i

End If

If ind = 17 Then For i = 1 To 16

For j = 9 To 25 Step 16

If (Image6(i).Top = Image1(j).Top And Image6(i).Left = Image1(j).Left) Or (Image7(i).Top = Image1(j).Top And

Image7(i).Left = Image1(j).Left) Then

blockway = True End If

Next j

Next i End If

End If

If piece = "Q" Then If Image1(ind).Left = Image1(position).Left Then

If ind < position Then

For i = 1 To 16

For j = ind + 1 To position - 1

If (Image6(i).Top = Image1(j).Top And Image6(i).Left = Image1(j).Left) Or (Image7(i).Top = Image1(j).Top And

Image7(i).Left = Image1(j).Left) Then

blockway = True End If

Next j

Next i End If

If ind > position + 1 Then

For i = 1 To 16 For j = ind - 1 To position + 1 Step -1

If (Image6(i).Top = Image1(j).Top And Image6(i).Left =

Image1(j).Left) Or (Image7(i).Top = Image1(j).Top And Image7(i).Left = Image1(j).Left) Then

blockway = True

End If Next j

Next i

End If Else

If Image1(ind).Top = Image1(position).Top Then

If ind < position Then For i = 1 To 16

For j = ind + 8 To position - 8 Step 8

If (Image6(i).Top = Image1(j).Top And Image6(i).Left = Image1(j).Left) Or (Image7(i).Top = Image1(j).Top And

Image7(i).Left = Image1(j).Left) Then blockway = True

End If

Next j Next i

End If

If ind > position Then For i = 1 To 16

For j = ind - 8 To position + 8 Step -8

If (Image6(i).Top = Image1(j).Top And Image6(i).Left = Image1(j).Left) Or (Image7(i).Top = Image1(j).Top And

Image7(i).Left = Image1(j).Left) Then

blockway = True End If

Next j

Next i End If

Else

If Image1(ind).Tag = Image1(position).Tag Then If ind < position Then

For i = 1 To 16

For k = position To 1 Step -9

If ind = k Then

For j = ind + 9 To position - 9 Step 9

If (Image6(i).Top = Image1(j).Top And Image6(i).Left = Image1(j).Left) Or (Image7(i).Top = Image1(j).Top And

Image7(i).Left = Image1(j).Left) Then

blockway = True End If

Next j

End If Next k

For k = position To 1 Step -7

If ind = k Then For j = ind + 7 To position - 7 Step 7

If (Image6(i).Top = Image1(j).Top And Image6(i).Left =

Image1(j).Left) Or (Image7(i).Top = Image1(j).Top And Image7(i).Left = Image1(j).Left) Then

blockway = True

End If Next j

End If

Next k

Page 114: PC-Based Electronic Chess Board Game

Appendix D D-65

Next i

End If If ind > position Then

For i = 1 To 16

For k = position To 64 Step 9 If ind = k Then

For j = ind - 9 To position + 9 Step -9

If (Image6(i).Top = Image1(j).Top And Image6(i).Left = Image1(j).Left) Or (Image7(i).Top = Image1(j).Top And

Image7(i).Left = Image1(j).Left) Then

blockway = True End If

Next j

End If Next k

For k = position To 64 Step 7

If ind = k Then For j = ind - 7 To position + 7 Step -7

If (Image6(i).Top = Image1(j).Top And Image6(i).Left =

Image1(j).Left) Or (Image7(i).Top = Image1(j).Top And Image7(i).Left = Image1(j).Left) Then

blockway = True

End If Next j

End If

Next k Next i

End If End If

End If

End If End If

End If

Case "B" If Not bpicked Then

If position - 9 > 0 Then

If Image1(position).Tag = Image1(position - 9).Tag Then tagcounter = tagcounter + 1

For j = 1 To 16

If Image7(j).Top = Image1(position - 9).Top And Image7(j).Left = Image1(position - 9).Left Then

counter = counter + 1

End If Next j

End If

End If If position - 7 > 0 Then

If Image1(position).Tag = Image1(position - 7).Tag Then

tagcounter = tagcounter + 1

For j = 1 To 16

If Image7(j).Top = Image1(position - 7).Top And

Image7(j).Left = Image1(position - 7).Left Then counter = counter + 1

End If

Next j End If

End If

If position + 9 < 65 Then If Image1(position).Tag = Image1(position + 9).Tag Then

tagcounter = tagcounter + 1

For j = 1 To 16 If Image7(j).Top = Image1(position + 9).Top And

Image7(j).Left = Image1(position + 9).Left Then

counter = counter + 1 End If

Next j

End If End If

If position + 7 < 65 Then

If Image1(position).Tag = Image1(position + 7).Tag Then

tagcounter = tagcounter + 1

For j = 1 To 16 If Image7(j).Top = Image1(position + 7).Top And

Image7(j).Left = Image1(position + 7).Left Then

counter = counter + 1 End If

Next j

End If End If

If tagcounter = counter Then

blockway = True End If

Else

If Image1(ind).Tag = Image1(position).Tag Then If ind < position Then

For i = 1 To 16

For k = position To 1 Step -9 If ind = k Then

For j = ind + 9 To position - 9 Step 9

If (Image6(i).Top = Image1(j).Top And Image6(i).Left = Image1(j).Left) Or (Image7(i).Top = Image1(j).Top And

Image7(i).Left = Image1(j).Left) Then

blockway = True End If

Next j

End If Next k

For k = position To 1 Step -7 If ind = k Then

For j = ind + 7 To position - 7 Step 7

If (Image6(i).Top = Image1(j).Top And Image6(i).Left = Image1(j).Left) Or (Image7(i).Top = Image1(j).Top And

Image7(i).Left = Image1(j).Left) Then

blockway = True End If

Next j

End If Next k

Next i

End If If ind > position Then

For i = 1 To 16

For k = position To 64 Step 9 If ind = k Then

For j = ind - 9 To position + 9 Step -9

If (Image6(i).Top = Image1(j).Top And Image6(i).Left = Image1(j).Left) Or (Image7(i).Top = Image1(j).Top And

Image7(i).Left = Image1(j).Left) Then

blockway = True

End If

Next j

End If Next k

For k = position To 64 Step 7

If ind = k Then For j = ind - 7 To position + 7 Step -7

If (Image6(i).Top = Image1(j).Top And Image6(i).Left =

Image1(j).Left) Or (Image7(i).Top = Image1(j).Top And Image7(i).Left = Image1(j).Left) Then

blockway = True

End If Next j

End If

Next k Next i

End If

End If End If

End Select

End If

Page 115: PC-Based Electronic Chess Board Game

Appendix D D-66

end_blockway:

End Function

Private Function pawnpromote() As Boolean

If bpicked = True Then For i = 8 To 64 Step 8

If (position + 1) = i Then

pawnpromote = True End If

Next i

End If

If picked = True Then

For i = 1 To 57 Step 8 If (position - 1) = i Then

pawnpromote = True

End If Next i

End If

End Function

Private Function pawnpromotion(ind As Integer)

Label3.Visible = True For i = 1 To 4

image10(i).Visible = True

Next i Command2.Visible = True

If bpicked = True Then image10(1).Picture = LoadPicture(App.Path &

"/images/axiomblack.gif")

image10(2).Picture = LoadPicture(App.Path & "/images/horseblack.gif")

image10(3).Picture = LoadPicture(App.Path &

"/images/pirgoblack.gif") image10(4).Picture = LoadPicture(App.Path &

"/images/QueenBlack.gif")

Image7(piecenum).Top = Image1(ind).Top Image7(piecenum).Left = Image1(ind).Left

End If

If picked = True Then image10(1).Picture = LoadPicture(App.Path &

"/images/axiomwhite.gif")

image10(2).Picture = LoadPicture(App.Path & "/images/horsewhite.gif")

image10(3).Picture = LoadPicture(App.Path &

"/images/pirgowhite.gif") image10(4).Picture = LoadPicture(App.Path &

"/images/QueenWhite.gif")

Image6(piecenum).Top = Image1(ind).Top

Image6(piecenum).Left = Image1(ind).Left

End If

Timer2.Enabled = False Timer3.Enabled = False

End Function

Private Function perpetual_check() As Boolean Dim bilang As Integer, bilang2 As Integer

bilang2 = 0

perpetual_check = False For i = 1 To 16

white_pos(i, move_count) = Str(Image6(i).Top) &

Str(Image6(i).Left) black_pos(i, move_count) = Str(Image7(i).Top) &

Str(Image7(i).Left)

Next i If move_count > 7 Then

For j = move_count To 0 Step -1

bilang = 0 For i = 1 To 16

If white_pos(i, j) = white_pos(i, move_count) And

black_pos(i, j) = black_pos(i, move_count) Then

bilang = bilang + 1

End If Next i

If bilang = 16 Then

bilang2 = bilang2 + 1 If bilang2 = 3 Then

perpetual_check = True

GoTo end_perpetual_check End If

End If

Next j End If

move_count = move_count + 1

end_perpetual_check: draw = perpetual_check

End Function

Private Function restart() boolforpatong = False

bturn2 = 0

trgr = True trigger = False

counter = 0

column = 0 opl = 0

posopl = 0

Out 890, 41 kingblackmoved = False

kingwhitemoved = False rightrookwhitemoved = False

leftrookwhitemoved = False

rightrookblackmoved = False leftrookblackmoved = False

blackturn = False

whiteturn = False picked = False

bpicked = False

position = 0 castling = False

checked = False

opponentpiecelifted = False move_count = 1

mcastling = True

castling_queen_side = True castling_king_side = True

mcastlingb = True

castling_queen_sideb = True castling_king_sideb = True

checkmate = False

draw = False

takboctr = 0

kukai = ""

run_cnt = 0 hula = False

ppp = 0

For i = 1 To 16 white_pos(i, 0) = Str(Image6(i).Top) & Str(Image6(i).Left)

black_pos(i, 0) = Str(Image7(i).Top) & Str(Image7(i).Left)

Next i Call load_color

lblmessage.Top = Me.Top

lblmessage.Width = Me.Width Frame1.Visible = False

For t = 1 To 8 whitepawnmoved(t) = False

blackpawnmoved(t) = False

enpassantpiecew(t) = False enpassantpieceb(t) = False

Next

Page 116: PC-Based Electronic Chess Board Game

Appendix D D-67

lst_moves.Clear

For i = 0 To 1 Label7(i).Caption = ""

Next i

For i = 1 To 8 Image7(i).Picture = LoadPicture(App.Path &

"/images/pionblack.gif")

Image6(i).Picture = LoadPicture(App.Path & "/images/pionwhite.gif")

Image7(i).Tag = "P"

Image6(i).Tag = "P" enpassantpiecew(i) = False

enpassantpieceb(i) = False

Next i

g = 0

For t = 7 To 63 Step 8 g = g + 1

Image6(g).Top = Image1(t).Top

Image6(g).Left = Image1(t).Left Next

g = 8 For t = 8 To 64 Step 8

g = g + 1

Image6(g).Top = Image1(t).Top Image6(g).Left = Image1(t).Left

Next

g = 0

For t = 2 To 58 Step 8 g = g + 1

Image7(g).Top = Image1(t).Top

Image7(g).Left = Image1(t).Left Next

g = 8 For t = 1 To 57 Step 8

g = g + 1

Image7(g).Top = Image1(t).Top Image7(g).Left = Image1(t).Left

Next

For i = 1 To 16

Image6(i).Visible = False

Image7(i).Visible = False Next i

Label10.Caption = ""

End Function

Private Sub mnuabout_Click() x = MsgBox("PC-Based Electronic Chess Board Game----

simulator----" & vbCrLf & vbCrLf & "Developers:" &

vbCrLf & vbCrLf & " -Peter John Saliente" & vbCrLf & " -Bernoullie Ulama" & vbCrLf & " -Ron Jairo Cuarteros",

vbOKOnly, "About") = vbOK

End Sub

Private Sub mnuAutoSave_Click()

If mnuAutoSave.Caption = "AutoSave ON" Then mnuAutoSave.Caption = "AutoSave OFF"

Else

mnuAutoSave.Caption = "AutoSave ON" End If

End Sub

Private Sub mnuExit_Click()

Unload Me

End Sub

Private Sub mnuLoadGame_Click(): Dim file As String ' show open box

CommonDialog1.InitDir = App.Path & "\save"

CommonDialog1.ShowOpen

file = Right(CommonDialog1.FileName, 4)

If file = ".txt" Then loadfilelocation = CommonDialog1.FileName

End If

Me.Tag = CommonDialog1.FileTitle ' input files into text1.text

If loadfilelocation <> "" Then

Out 890, 32 'sets clock to low Call load_color

column = 0

Timer2.Enabled = False Timer3.Enabled = False

sum1 = 0

sum2 = 0 For i = 1 To 16

Image6(i).Visible = False

Image7(i).Visible = False Next i

lst_moves.Clear

Open loadfilelocation For Input As #1 For i = 1 To 16

If Not EOF(1) Then Input #1, Data

Image6(i).Left = Data

End If Next i

For i = 1 To 16 If Not EOF(1) Then

Input #1, Data

Image6(i).Top = Data End If

Next i

For i = 1 To 16 If Not EOF(1) Then

Input #1, Data

Image6(i).Tag = Data If i < 9 Then

For j = 9 To 16

If Image6(i).Tag = Image6(j).Tag Then Image6(i).Picture = Image6(j).Picture

End If

Next j

End If

End If

Next i

For i = 1 To 16

If Not EOF(1) Then Input #1, Data

Image7(i).Left = Data

End If Next i

For i = 1 To 16

If Not EOF(1) Then Input #1, Data

Image7(i).Top = Data

End If Next i

For i = 1 To 16

If Not EOF(1) Then Input #1, Data

Image7(i).Tag = Data

If i < 9 Then

Page 117: PC-Based Electronic Chess Board Game

Appendix D D-68

For j = 9 To 16

If Image7(i).Tag = Image7(j).Tag Then Image7(i).Picture = Image7(j).Picture

End If

Next j End If

End If

Next i

Input #1, Data

Label7(1).Caption = Data If Data = "W" Then

whiteturn = True

blackturn = False Else

blackturn = True

whiteturn = False End If

Input #1, Data Label10.Caption = Data

Input #1, Data timerw(0) = Data

Input #1, Data

timerw(1) = Data Input #1, Data

timerb(0) = Data Input #1, Data

timerb(1) = Data

If Not EOF(1) Then Input #1, Data

bturn2 = Data

End If For i = 0 To bturn2

If Not EOF(1) Then

Input #1, Data If Data <> "" Then

lst_moves.List(i) = Data

End If End If

Next i

'**********************************************************

If Not EOF(1) Then

Input #1, Data kingblackmoved = Data

End If

If Not EOF(1) Then

Input #1, Data

kingwhitemoved = Data

End If If Not EOF(1) Then

Input #1, Data

rightrookwhitemoved = Data End If

If Not EOF(1) Then

Input #1, Data leftrookwhitemoved = Data

End If

If Not EOF(1) Then Input #1, Data

rightrookblackmoved = Data

End If If Not EOF(1) Then

Input #1, Data

leftrookblackmoved = Data End If

If Not EOF(1) Then

Input #1, Data

mcastling = Data

End If If Not EOF(1) Then

Input #1, Data

castling_queen_side = Data End If

If Not EOF(1) Then

Input #1, Data castling_king_side = Data

End If

If Not EOF(1) Then Input #1, Data

mcastlingb = Data

End If If Not EOF(1) Then

Input #1, Data

castling_queen_sideb = Data End If

If Not EOF(1) Then

Input #1, Data castling_king_sideb = Data

End If

If Not EOF(1) Then Input #1, Data

checkmate = Data

End If If Not EOF(1) Then

Input #1, Data draw = Data

End If

If Not EOF(1) Then Input #1, Data

move_count = Data

Input #1, Data hula = Data

End If

For t = 1 To 8

If Not EOF(1) Then

Input #1, Data whitepawnmoved(t) = Data

End If

If Not EOF(1) Then Input #1, Data

blackpawnmoved(t) = Data

End If If Not EOF(1) Then

Input #1, Data

enpassantpiecew(t) = Data

End If

If Not EOF(1) Then

Input #1, Data enpassantpieceb(t) = Data

End If

Next t

For i = 0 To move_count

For j = 1 To 16 If Not EOF(1) Then

Input #1, Data

white_pos(j, i) = Data End If

If Not EOF(1) Then

Input #1, Data black_pos(j, i) = Data

End If

Next j Next i

Close #1

Page 118: PC-Based Electronic Chess Board Game

Appendix D D-69

'MsgBox ("Set the time on the chess board" & vbCrLf &

vbCrLf & "White" & vbCrLf & timerw(1) & ":" & timerw(0) & vbCrLf & vbCrLf & "Black" & vbCrLf & timerb(1) & ":"

& timerb(0))

If Label10.Caption = "Professional" Then gamemode = "Professional"

time = 0

For i = 1 To 16 Image6(i).Visible = True

Image7(i).Visible = True

Next i Else

gamemode = "Amateur"

time = 0 End If

blink_timer.Enabled = False

Timer4.Enabled = True mnuLoadGame.Enabled = False

End If

cmd_next.Visible = False cmd_prev.Visible = False

CommonDialog1.FileName = ""

loadfilelocation = "" End Sub

Private Sub mnuNewGame_Click() mnuSaveGame.Enabled = False

savefilelocation = "" Call restart

Timer2.Enabled = False

Timer3.Enabled = False Label7(1).Caption = "W"

whiteturn = True

Me.Enabled = False Form3.Show

cmd_next.Visible = False

cmd_prev.Visible = False End Sub

Private Sub mnuRun_Click() If move_count > 0 Then

cmd_next.Visible = True

cmd_prev.Visible = True Timer1.Enabled = False

Timer2.Enabled = False

Timer3.Enabled = False Timer4.Enabled = False

Timer5.Enabled = False

Timer6.Enabled = False

For i = 1 To 16

For j = 1 To 64

strTemp1 = Str(Image1(j).Top) & Str(Image1(j).Left) If white_pos(i, 0) = strTemp1 Then

Image6(i).Top = Image1(j).Top

Image6(i).Left = Image1(j).Left End If

If black_pos(i, 0) = strTemp1 Then

Image7(i).Top = Image1(j).Top Image7(i).Left = Image1(j).Left

End If

Next j Next i

mnuLoadGame.Enabled = True

For i = 1 To 16 Image6(i).Visible = True

Image7(i).Visible = True

Next i End If

End Sub

Private Sub mnuSaveGame_Click()

If Not picked And Not bpicked Then listcnt = lst_moves.ListCount

turn = Label7(1).Caption

' loads save as box On Error GoTo errhandler

With CommonDialog1

.CancelError = True

.InitDir = App.Path & "\save"

.ShowSave

End With savefilelocation = CommonDialog1.FileName

errhandler:

If Err.Number = 32755 Then GoTo Cancel

End If

' append saves over file if it assists If Dir(savefilelocation) = "" Then

If savefilelocation <> "" Then

over: Open savefilelocation For Output As #1 For i = 1 To 16

Print #1, Image6(i).Left

Next i For i = 1 To 16

Print #1, Image6(i).Top

Next i For i = 1 To 16

Print #1, Image6(i).Tag Next i

For i = 1 To 16

Print #1, Image7(i).Left Next i

For i = 1 To 16

Print #1, Image7(i).Top Next i

For i = 1 To 16

Print #1, Image7(i).Tag Next i

Print #1, turn

If gamemode = "Professional" Then

Print #1, "Professional" Else

Print #1, "Amateur"

End If

Print #1, timerw(0)

Print #1, timerw(1)

Print #1, timerb(0)

Print #1, timerb(1)

Print #1, listcnt - 1

For i = 0 To listcnt - 1 Print #1, lst_moves.List(i)

Next i

'******************************************************

Print #1, kingblackmoved

Print #1, kingwhitemoved Print #1, rightrookwhitemoved

Print #1, leftrookwhitemoved

Print #1, rightrookblackmoved Print #1, leftrookblackmoved

Print #1, mcastling Print #1, castling_queen_side

Print #1, castling_king_side

Print #1, mcastlingb

Page 119: PC-Based Electronic Chess Board Game

Appendix D D-70

Print #1, castling_queen_sideb

Print #1, castling_king_sideb Print #1, checkmate

Print #1, draw

Print #1, move_count - 1 Print #1, hula

For t = 1 To 8 Print #1, whitepawnmoved(t)

Print #1, blackpawnmoved(t)

Print #1, enpassantpiecew(t) Print #1, enpassantpieceb(t)

Next t

For i = 0 To move_count - 1

For j = 1 To 16

Print #1, white_pos(j, i) Print #1, black_pos(j, i)

Next j

Next i Close #1

Timer2.Enabled = False

Timer3.Enabled = False If overwrite = 7 Then

MsgBox ("File Saved")

overwrite = -1 End If

End If Else

MsgBox ("Filename already exist")

overwrite = MsgBox("Over write existing file?", vbYesNo) = vbYes And vbNo

If overwrite = 7 Then

GoTo over End If

End If

Else error = MsgBox("Error saving!" & vbCrLf & vbCrLf &

"Please end the turn" & vbCrLf & "before you save the

game" & vbCrLf & vbCrLf & "The game is not yet save..", vbOKOnly, "Error") = vbOK

End If

CommonDialog1.FileName = "" savefilelocation = ""

Timer2.Enabled = True

Timer3.Enabled = True cmd_next.Visible = False

cmd_prev.Visible = False

Cancel:

End Sub

Private Sub protime_Timer() ProSw = Inp(889)

If ProSw = 94 Then

whiteturnoff (ProTaba) protime.Enabled = False

End If

If ProSw = 110 Then blackturnoff (ProTaba)

protime.Enabled = False

End If End Sub

Private Sub Timer1_Timer() Dim tmr1var As Integer

If gamemode = "Amateur" Then

If time < 8 Then Out 890, 34

datainput = Inp(888)

For j = 0 To time - 1

tmr1var = datainput

anong_bit = 128 For i = (1 + (j * 8)) To (8 + (j * 8))

If tmr1var >= anong_bit Then

block(i) = 1 tmr1var = tmr1var - anong_bit

Else

block(i) = 0 End If

anong_bit = anong_bit / 2

Next i Next j

For i = 1 To 64

If block(i) = 1 Then Label5(i).BackColor = &HFF&

Else

Label5(i).BackColor = &H8000000F End If

Next i

If datainput = 195 Then time = time + 1

For i = 1 To 64

For j = time To time + 8 Step 8 If Image1(i).Top = Image6(j).Top And Image1(i).Left =

Image6(j).Left Then

Image6(j).Visible = True

End If If Image1(i).Top = Image7(j).Top And Image1(i).Left =

Image7(j).Left Then

Image7(j).Visible = True

End If

Next j Next i

Out 890, 38

End If Else

anong_bit = 128

Out 890, 34 datainput = Inp(888)

For j = 0 To time - 1

tmr1var = datainput anong_bit = 128

For i = (1 + (j * 8)) To (8 + (j * 8))

If tmr1var >= anong_bit Then block(i) = 1

tmr1var = tmr1var - anong_bit

Else

block(i) = 0

End If

anong_bit = anong_bit / 2 Next i

Next j

For i = 1 To 64 If block(i) = 1 Then

Label5(i).BackColor = &HFF&

Else Label5(i).BackColor = &H8000000F

End If

Next i If datainput = 195 Then

time = 0

Timer1.Enabled = False Form2.Text1.Text = ""

Form2.Show

turn = "W" Me.Enabled = False

mnuSaveGame.Enabled = True

Out 890, 32

Page 120: PC-Based Electronic Chess Board Game

Appendix D D-71

End If

End If Else

time = time + 1

If time < 16 Then If Not trigger Then

Out 890, 34

trigger = Not trigger anong_bit = 128

datainput = Inp(888)

tmr1var = datainput For i = (1 + column) To (8 + column)

If tmr1var >= anong_bit Then

meralco(i) = 1 tmr1var = tmr1var - anong_bit

Else

meralco(i) = 0 End If

anong_bit = anong_bit / 2

block(i) = meralco(i) Next i

column = column + 8

Else Out 890, 38

trigger = Not trigger

End If Else

Out 890, 32 trigger = False

time = 0

column = 0 End If

For i = 1 To 64

If block(i) = 1 Then timer4cnt = timer4cnt + 1

End If

Next i If timer4cnt = 32 Then

Timer1.Enabled = False

mnuSaveGame.Enabled = True Form2.Text1.Text = ""

Form2.Show

turn = "W" Me.Enabled = False

Else

timer4cnt = 0 End If

End If

End Sub

Private Function load_color()

'Loading every blocks/Squares Image and adds tag in every blocks

For i = 1 To 7 Step 2

Image1(i).Picture = LoadPicture(App.Path & "/images/white.jpg")

Image1(i).Tag = "white"

Image1(i + 1).Picture = LoadPicture(App.Path & "/images/black.jpg")

Image1(i + 1).Tag = "black"

Image1(i + 16).Picture = LoadPicture(App.Path & "/images/white.jpg")

Image1(i + 16).Tag = "white"

Image1(i + 17).Picture = LoadPicture(App.Path & "/images/black.jpg")

Image1(i + 17).Tag = "black"

Image1(i + 32).Picture = LoadPicture(App.Path & "/images/white.jpg")

Image1(i + 32).Tag = "white"

Image1(i + 33).Picture = LoadPicture(App.Path &

"/images/black.jpg") Image1(i + 33).Tag = "black"

Image1(i + 48).Picture = LoadPicture(App.Path &

"/images/white.jpg") Image1(i + 48).Tag = "white"

Image1(i + 49).Picture = LoadPicture(App.Path &

"/images/black.jpg") Image1(i + 49).Tag = "black"

Next i

For g = 9 To 15 Step 2 Image1(g).Picture = LoadPicture(App.Path &

"/images/black.jpg")

Image1(g).Tag = "black" Image1(g + 1).Picture = LoadPicture(App.Path &

"/images/white.jpg")

Image1(g + 1).Tag = "white" Image1(g + 16).Picture = LoadPicture(App.Path &

"/images/black.jpg")

Image1(g + 16).Tag = "black" Image1(g + 17).Picture = LoadPicture(App.Path &

"/images/white.jpg")

Image1(g + 17).Tag = "white" Image1(g + 32).Picture = LoadPicture(App.Path &

"/images/black.jpg")

Image1(g + 32).Tag = "black" Image1(g + 33).Picture = LoadPicture(App.Path &

"/images/white.jpg") Image1(g + 33).Tag = "white"

Image1(g + 48).Picture = LoadPicture(App.Path &

"/images/black.jpg") Image1(g + 48).Tag = "black"

Image1(g + 49).Picture = LoadPicture(App.Path &

"/images/white.jpg") Image1(g + 49).Tag = "white"

Next g

End Function

Private Sub Timer2_Timer(): Dim placed As Integer

time = time + 1 If time < 16 Then

If Not trigger Then

Out 890, 43 trigger = Not trigger

anong_bit = 128

datainput = Inp(888) maliwanag_ang_buhay = datainput

For i = (1 + column) To (8 + column)

placed = i

If maliwanag_ang_buhay >= anong_bit Then

meralco(i) = 1

maliwanag_ang_buhay = maliwanag_ang_buhay - anong_bit Else

meralco(i) = 0

End If anong_bit = anong_bit / 2

block(i) = meralco(i)

If block(i) <> tmp(i) Then

If block(i) = 0 Then

Label5(i).BackColor = &H8000000F For j = 1 To 16

If whiteturn Then

Out 890, 42 If Not picked Then

If Image6(j).Left = Image1(i).Left And Image6(j).Top =

Image1(i).Top Then piece = Image6(j).Tag

piecenum = j

position = i

Page 121: PC-Based Electronic Chess Board Game

Appendix D D-72

If Not opencheck Then

If Not blockway(placed) And nenah Then Image6(j).Left = Me.Width

Image6(j).Top = Me.Width

picked = True If gamemode = "Amateur" Then

glow_tile

End If Call findlabel(position)

movefrom = Label7(0).Caption

Else If abletomove Then

Image6(j).Left = Me.Width

Image6(j).Top = Me.Width picked = True

If gamemode = "Amateur" Then

glow_tile End If

Call findlabel(position)

movefrom = Label7(0).Caption Else

kukai = "Can not be Move!" Timer6.Enabled = True

End If

End If Else

kukai = "Open Check!" Timer6.Enabled = True

End If

End If Else

If castling Then

If Image6(j).Top = Image1(i).Top And Image6(j).Left = Image1(i).Left Then

If j = rook Then

Image6(j).Top = Me.Width Image6(j).Left = Me.Width

End If

End If Else

If Not opponentpiecelifted Then

Call yeswiz(placed) Else

Image7(opl).Top = Me.Width

Image7(opl).Left = Me.Width End If

End If

End If

End If

If blackturn Then Out 890, 35

If Not bpicked Then

If Image7(j).Left = Image1(i).Left And Image7(j).Top = Image1(i).Top Then

piece = Image7(j).Tag

piecenum = j position = i

If Not opencheck Then

If Not blockway(placed) And nenah Then Image7(j).Left = Me.Width

Image7(j).Top = Me.Width

bpicked = True If gamemode = "Amateur" Then

glow_tile

End If Call findlabel(position)

movefrom = Label7(0).Caption

Else

If abletomove Then

Image7(j).Left = Me.Width Image7(j).Top = Me.Width

bpicked = True

If gamemode = "Amateur" Then glow_tile

End If

Call findlabel(position) movefrom = Label7(0).Caption

Else

kukai = "Can not be Move!" Timer6.Enabled = True

End If

End If Else

kukai = "Open Check!"

Timer6.Enabled = True End If

End If

Else If castling Then

If Image7(j).Top = Image1(i).Top And Image7(j).Left =

Image1(i).Left Then If j = rook Then

Image7(j).Top = Me.Width

Image7(j).Left = Me.Width End If

End If Else

If Not opponentpiecelifted Then

Call yeswiz(placed) Else

Image6(opl).Top = Me.Width

Image6(opl).Left = Me.Width End If

End If

End If End If

Next j

Else ' block =1 Label5(i).BackColor = &HFF&

pawnpromoted = False

If whiteturn And picked Then If castling Then

If i = rookdes Then

reset_changed_tiles kukai = "CASTLING!"

Timer6.Enabled = True

Image6(rook).Top = Image1(i).Top

Image6(rook).Left = Image1(i).Left

If gamemode = "Amateur" Then Call whiteturnoff(rookdes)

Else

ProTaba = rookdes protime.Enabled = True

End If

castling = False Else

kukai = "Illegal Move!"

Timer6.Enabled = True End If

Else

If i <> position Then blocked = blockway(placed)

pawnpromoted = pawnpromote

Call piecemoves(placed) Else

If gamemode = "Amateur" Then

If Not opponentpiecelifted Then

Page 122: PC-Based Electronic Chess Board Game

Appendix D D-73

Image6(piecenum).Left = Image1(i).Left Image6(piecenum).Top = Image1(i).Top

Call reset_changed_tiles picked = False

Else

kukai = "Illegal Move!" Timer6.Enabled = True

End If

Else kukai = "Touch Move!"

Timer6.Enabled = True

End If End If

End If

End If If blackturn And bpicked Then

If castling Then

If i = rookdes Then reset_changed_tiles

kukai = "CASTLING!"

Timer6.Enabled = True Image7(rook).Top = Image1(i).Top

Image7(rook).Left = Image1(i).Left

If gamemode = "Amateur" Then Call blackturnoff(rookdes)

Else ProTaba = rookdes

protime.Enabled = True

End If castling = False

Else

kukai = "Illegal Move!" Timer6.Enabled = True

End If

Else If i <> position Then

blocked = blockway(placed)

pawnpromoted = pawnpromote Call piecemoves(placed)

Else

If gamemode = "Amateur" Then If Not opponentpiecelifted Then

Image7(piecenum).Left = Image1(i).Left

Image7(piecenum).Top = Image1(i).Top

Call reset_changed_tiles

bpicked = False

Else

kukai = "Illegal Move!"

Timer6.Enabled = True End If

Else

kukai = "Touch Move!" Timer6.Enabled = True

End If

End If End If

End If

End If End If

Label5(i).Caption = block(i)

tmp(i) = block(i) Next i

column = column + 8

Else If blackturn Then

Out 890, 39

trigger = Not trigger

End If

If whiteturn Then Out 890, 46

trigger = Not trigger

End If End If

Else

If blackturn Then Out 890, 33

trigger = False

time = 0 column = 0

End If

If whiteturn Then Out 890, 40

trigger = False

time = 0 column = 0

End If

End If

End Sub

Private Function yeswiz(ind As Integer)

opponentpiecelifted = False

If picked Then Select Case piece

Case "P" If OpenCheckTilesCount = 0 Then

For i = 1 To 16

If Image7(i).Left = Image1(ind).Left And Image7(i).Top = Image1(ind).Top Then

opl = i

posopl = ind If ind = position - 9 Or ind = position + 7 Then

opponentpiecelifted = True

End If If i < 9 And beyond(position) Then

If ind = position + 8 Then

posdes = ind - 1 opponentpiecelifted = True

Else

If ind = position - 8 Then posdes = ind - 1

opponentpiecelifted = True

End If End If

End If

End If

Next i

Else

For i = 1 To 16 If Image7(i).Left = Image1(ind).Left And Image7(i).Top =

Image1(ind).Top And OnOpenCheckTiles(ind) Then

opl = i posopl = ind

If ind = position - 9 Or ind = position + 7 Then

opponentpiecelifted = True End If

If i < 9 And (ind = position + 8 Or ind = position - 8) And

beyond(position) Then opponentpiecelifted = True

End If

End If Next i

If Not OnOpenCheckTiles(ind) Then

End If

End If

Case "N"

Page 123: PC-Based Electronic Chess Board Game

Appendix D D-74

For i = 1 To 16

If Image7(i).Left = Image1(ind).Left And Image7(i).Top = Image1(ind).Top Then

opl = i

posopl = ind If Image1(position).Tag <> Image1(ind).Tag And (ind =

position - 6 Or ind = position - 10 Or ind = position - 15 Or

ind = position - 17 Or ind = position + 6 Or ind = position + 10 Or ind = position + 15 Or ind = position + 17) Then

opponentpiecelifted = True

End If End If

Next i

Case "R" For i = 1 To 16

If Image7(i).Left = Image1(ind).Left And Image7(i).Top =

Image1(ind).Top Then opl = i

posopl = ind

If Not blockway(ind) And (Image1(ind).Left = Image1(position).Left Or Image1(ind).Top =

Image1(position).Top) Then

opponentpiecelifted = True End If

End If

Next i Case "B"

For i = 1 To 16 If Image7(i).Left = Image1(ind).Left And Image7(i).Top =

Image1(ind).Top Then

opl = i posopl = ind

If Not blockway(ind) And Image1(ind).Tag =

Image1(position).Tag Then If ind < position Then

For k = 7 To 9 Step 2

For j = position To 1 Step -k If ind = j Then

opponentpiecelifted = True

End If Next j

Next k

End If If ind > position Then

For k = 7 To 9 Step 2

For j = position To 64 Step k If ind = j Then

opponentpiecelifted = True

End If

Next j

Next k

End If End If

End If

Next i Case "Q"

For i = 1 To 16

If Image7(i).Left = Image1(ind).Left And Image7(i).Top = Image1(ind).Top Then

opl = i

posopl = ind If Not blockway(ind) Then

If Image1(ind).Tag = Image1(position).Tag Then

If ind < position Then For k = 7 To 9 Step 2

For j = position To 1 Step -k

If ind = j Then opponentpiecelifted = True

End If

Next j

Next k

End If If ind > position Then

For k = 7 To 9 Step 2

For j = position To 64 Step k If ind = j Then

opponentpiecelifted = True

End If Next j

Next k

End If End If

If Image1(ind).Left = Image1(position).Left Or

Image1(ind).Top = Image1(position).Top Then opponentpiecelifted = True

End If

End If End If

Next i

Case "K" For i = 1 To 16

If Image7(i).Left = Image1(ind).Left And Image7(i).Top =

Image1(ind).Top Then opl = i

posopl = ind

If Not endbottom() And Not endtop() And (ind = position - 1 Or ind = position + 1 Or ind = position - 8 Or ind = position

+ 8 Or ind = position - 9 Or ind = position + 9 Or ind = position - 7 Or ind = position + 7) Then

opponentpiecelifted = True

Else If endbottom() And (ind = position - 1 Or ind = position - 9

Or ind = position + 7 Or ind = position - 8 Or ind = position

+ 8) Then opponentpiecelifted = True

Else

If endtop() And (ind = position + 1 Or ind = position + 9 Or ind = position - 7 Or ind = position - 8 Or ind = position + 8)

Then

opponentpiecelifted = True End If

End If

End If End If

Next i

End Select End If

If bpicked Then

Select Case piece

Case "P"

If OpenCheckTilesCount = 0 Then For i = 1 To 16

If Image6(i).Left = Image1(ind).Left And Image6(i).Top =

Image1(ind).Top Then opl = i

posopl = ind

If ind = position + 9 Or ind = position - 7 Then opponentpiecelifted = True

End If

If i < 9 And (ind = position + 8 Or ind = position - 8) And beyond(position) Then

opponentpiecelifted = True

End If End If

Next i

Else For i = 1 To 16

If Image6(i).Left = Image1(ind).Left And Image6(i).Top =

Image1(ind).Top And OnOpenCheckTiles(ind) Then

Page 124: PC-Based Electronic Chess Board Game

Appendix D D-75

opl = i

posopl = ind If ind = position + 9 Or ind = position - 7 Then

opponentpiecelifted = True

End If If i < 9 And beyond(position) Then

If ind = position + 8 Then

opponentpiecelifted = True posdes = ind + 1

Else

If ind = position - 8 Then opponentpiecelifted = True

posdes = ind + 1

End If End If

End If

End If Next i

If Not OnOpenCheckTiles(ind) Then

End If

End If

Case "N" For i = 1 To 16

If Image6(i).Left = Image1(ind).Left And Image6(i).Top =

Image1(ind).Top Then opl = i

posopl = ind If Image1(position).Tag <> Image1(ind).Tag And (ind =

position - 6 Or ind = position - 10 Or ind = position - 15 Or

ind = position - 17 Or ind = position + 6 Or ind = position + 10 Or ind = position + 15 Or ind = position + 17) Then

opponentpiecelifted = True

End If End If

Next i

Case "R" For i = 1 To 16

If Image6(i).Left = Image1(ind).Left And Image6(i).Top =

Image1(ind).Top Then opl = i

posopl = ind

If Not blockway(ind) And (Image1(ind).Left = Image1(position).Left Or Image1(ind).Top =

Image1(position).Top) Then

opponentpiecelifted = True End If

End If

Next i

Case "B"

For i = 1 To 16

If Image6(i).Left = Image1(ind).Left And Image6(i).Top = Image1(ind).Top Then

opl = i

posopl = ind If Not blockway(ind) And Image1(ind).Tag =

Image1(position).Tag Then

If ind < position Then For k = 7 To 9 Step 2

For j = position To 1 Step -k

If ind = j Then opponentpiecelifted = True

End If

Next j Next k

End If

If ind > position Then For k = 7 To 9 Step 2

For j = position To 64 Step k

If ind = j Then

opponentpiecelifted = True

End If Next j

Next k

End If End If

End If

Next i Case "Q"

For i = 1 To 16

If Image6(i).Left = Image1(ind).Left And Image6(i).Top = Image1(ind).Top Then

opl = i

posopl = ind If Not blockway(ind) Then

If Image1(ind).Tag = Image1(position).Tag Then

If ind < position Then For k = 7 To 9 Step 2

For j = position To 1 Step -k

If ind = j Then opponentpiecelifted = True

End If

Next j Next k

End If

If ind > position Then For k = 7 To 9 Step 2

For j = position To 64 Step k If ind = j Then

opponentpiecelifted = True

End If Next j

Next k

End If End If

If Image1(ind).Left = Image1(position).Left Or

Image1(ind).Top = Image1(position).Top Then opponentpiecelifted = True

End If

End If End If

Next i

Case "K" For i = 1 To 16

If Image6(i).Left = Image1(ind).Left And Image6(i).Top =

Image1(ind).Top Then opl = i

posopl = ind

If Not endbottom() And Not endtop() And (ind = position - 1

Or ind = position + 1 Or ind = position - 8 Or ind = position

+ 8 Or ind = position - 9 Or ind = position + 9 Or ind =

position - 7 Or ind = position + 7) Then opponentpiecelifted = True

Else

If endbottom() And (ind = position - 1 Or ind = position - 9 Or ind = position + 7 Or ind = position - 8 Or ind = position

+ 8) Then

opponentpiecelifted = True Else

If endtop() And (ind = position + 1 Or ind = position + 9 Or

ind = position - 7 Or ind = position - 8 Or ind = position + 8) Then

opponentpiecelifted = True

End If End If

End If

End If Next i

End Select

End If

Page 125: PC-Based Electronic Chess Board Game

Appendix D D-76

If Not opponentpiecelifted Then

opl = 0 posopl = 0

End If

End Function

Private Function resetenpassant()

If picked Then For i = 1 To 8

enpassantpieceb(i) = False

Next i End If

If bpicked Then For i = 1 To 8

enpassantpiecew(i) = False

Next i End If

End Function

Private Function beyond(ind As Integer) As Boolean

If bpicked = True Then

For i = 5 To 61 Step 8 If ind = i Then

beyond = True

End If Next i

End If

If picked = True Then

For i = 4 To 60 Step 8 If ind = i Then

beyond = True

End If Next i

End If

End Function

Private Function abletomove() As Boolean

abletomove = False tagcounter = 0

counter = 0

If whiteturn Then Select Case piece

Case "P"

For i = 1 To 16 If (position - 9) > 0 Then

If Image7(i).Top = Image1(position - 9).Top And

Image7(i).Left = Image1(position - 9).Left Then

abletomove = True

Else

If i < 9 Then If Image1(position - 8).Top = Image7(i).Top And

Image1(position - 8).Left = Image7(i).Left And

enpassantpieceb(i) Then abletomove = True

End If

End If End If

End If

If (position + 7) < 65 Then If Image7(i).Top = Image1(position + 7).Top And

Image7(i).Left = Image1(position + 7).Left Then

abletomove = True Else

If i < 9 Then

If Image1(position + 8).Top = Image7(i).Top And Image1(position + 8).Left = Image7(i).Left And

enpassantpieceb(i) Then

abletomove = True

End If

End If End If

End If

Next i End Select

End If

If blackturn Then

Select Case piece

Case "P" For i = 1 To 16

If (position - 7) > 0 Then

If Image6(i).Top = Image1(position - 7).Top And Image6(i).Left = Image1(position - 7).Left Then

abletomove = True

Else If i < 9 Then

If Image1(position - 8).Top = Image6(i).Top And

Image1(position - 8).Left = Image6(i).Left And enpassantpiecew(i) Then

abletomove = True

End If End If

End If

End If If (position + 9) < 65 Then

If Image6(i).Top = Image1(position + 9).Top And Image6(i).Left = Image1(position + 9).Left Then

abletomove = True

Else If i < 9 Then

If Image1(position + 8).Top = Image6(i).Top And

Image1(position + 8).Left = Image6(i).Left And enpassantpiecew(i) Then

abletomove = True

End If End If

End If

End If Next i

End Select

End If End Function

Private Function findlabel(posit As Integer) Select Case posit

Case 1 To 8: Label7(0).Caption = "a"

Case 9 To 16: Label7(0).Caption = "b"

Case 17 To 24: Label7(0).Caption = "c"

Case 25 To 32: Label7(0).Caption = "d"

Case 33 To 40: Label7(0).Caption = "e" Case 41 To 48: Label7(0).Caption = "f"

Case 49 To 56: Label7(0).Caption = "g"

Case 57 To 64: Label7(0).Caption = "N" End Select

Select Case posit Case 8, 16, 24, 32, 40, 48, 56, 64: Label7(0).Caption =

Label7(0).Caption & "1"

Case 7, 15, 23, 31, 39, 47, 55, 63: Label7(0).Caption = Label7(0).Caption & "2"

Case 6, 14, 22, 30, 38, 46, 54, 62: Label7(0).Caption =

Label7(0).Caption & "3" Case 5, 13, 21, 29, 37, 45, 53, 61: Label7(0).Caption =

Label7(0).Caption & "4"

Case 4, 12, 20, 28, 36, 44, 52, 60: Label7(0).Caption = Label7(0).Caption & "5"

Case 3, 11, 19, 27, 35, 43, 51, 59: Label7(0).Caption =

Label7(0).Caption & "6"

Page 126: PC-Based Electronic Chess Board Game

Appendix D D-77

Case 2, 10, 18, 26, 34, 42, 50, 58: Label7(0).Caption =

Label7(0).Caption & "7" Case 1, 9, 17, 25, 33, 41, 49, 57: Label7(0).Caption =

Label7(0).Caption & "8"

End Select End Function

Private Function endtop() As Boolean endtop = False

For i = 1 To 57 Step 8

If Image1(position).Top = Image1(i).Top And Image1(position).Left = Image1(i).Left Then

endtop = True

End If Next i

End Function

Private Sub Timer3_Timer()

If gamemode = "Professional" Then

If whiteturn Then timerw(0) = timerw(0) - 1

If timerw(0) = -1 Then

timerw(0) = 59 timerw(1) = timerw(1) - 1

If timerw(1) = -1 Then

Timer3.Enabled = False Timer2.Enabled = False

End If End If

End If

If blackturn Then timerb(0) = timerb(0) - 1

If timerb(0) = -1 Then

timerb(0) = 59 timerb(1) = timerb(1) - 1

If timerb(1) = -1 Then

Timer3.Enabled = False Timer2.Enabled = False

End If

End If End If

For i = 0 To 1

If timerw(i) < 10 Then timerwhite(i).Caption = "0" & timerw(i)

Else

timerwhite(i).Caption = timerw(i) End If

If timerb(i) < 10 Then

timerblack(i).Caption = "0" & timerb(i)

Else

timerblack(i).Caption = timerb(i) End If

Next i

If timerw(1) = 0 And timerw(0) = 0 Then Timer2.Enabled = False

Timer3.Enabled = False

mnuSaveGame.Enabled = False MsgBox ("Out of Time! BLACK wins!")

End If

If timerb(1) = 0 And timerb(0) = 0 Then Timer2.Enabled = False

Timer3.Enabled = False

mnuSaveGame.Enabled = False MsgBox ("Out of Time! WHITE wins!")

End If

End If End Sub

Private Sub Timer4_Timer()

Dim tmr4var As Integer

If trgr Then Out 890, 34

sum1 = 0

trgr = Not trgr anong_bit = 128

If gamemode = "Amateur" Then

For j = (1 + time) To (8 + time) For i = 1 To 16

If (Image1(j).Top = Image6(i).Top And Image1(j).Left =

Image6(i).Left) Then If Image6(i).Visible = False Then

Image6(i).Visible = True

block(j) = 1 sum1 = sum1 + anong_bit

End If

End If If (Image1(j).Top = Image7(i).Top And Image1(j).Left =

Image7(i).Left) Then

If Image6(i).Visible = False Then Image7(i).Visible = True

block(j) = 1

sum1 = sum1 + anong_bit End If

End If

Next i anong_bit = anong_bit / 2

Next j Else

For j = (1 + time) To (8 + time)

For i = 1 To 16 If Image1(j).Top = Image6(i).Top And Image1(j).Left =

Image6(i).Left Then

sum1 = sum1 + anong_bit End If

If Image1(j).Top = Image7(i).Top And Image1(j).Left =

Image7(i).Left Then sum1 = sum1 + anong_bit

End If

Next i anong_bit = anong_bit / 2

Next j

End If Else

anong_bit = 128

datainput = Inp(888) If sum1 = datainput Then

time = time + 8

trgr = Not trgr

Out 890, 38

End If

End If If time > 56 Then

time = 0

trgr = True Out 890, 32

MsgBox ("Start game")

Timer2.Enabled = True Timer3.Enabled = True

Timer4.Enabled = False

column = 0 mnuSaveGame.Enabled = True

mnuLoadGame.Enabled = True

End If End Sub

Private Sub Timer5_Timer() If savefilelocation = "" Then

Form2.Show

Form1.Enabled = False

Page 127: PC-Based Electronic Chess Board Game

Appendix D D-78

Timer5.Enabled = False

End If End Sub

Private Sub Timer6_Timer()

takboctr = takboctr + 1 If takboctr < 100 Then

takbo (kukai)

Else takboctr = 0

Timer6.Enabled = False

lblmessage.Left = Me.Width End If

End Sub

Form 2

Private Sub Command1_Click() If Text1.Text <> "" Then

savefilelocation = App.Path & "\save\" & Text1.Text & ".txt"

If Dir(savefilelocation) = "" Then over: Open savefilelocation For Output As #1

For i = 1 To 16

Print #1, Form1.Image6(i).Left Next i

For i = 1 To 16

Print #1, Form1.Image6(i).Top Next i

For i = 1 To 16 Print #1, Form1.Image6(i).Tag

Next i

For i = 1 To 16 Print #1, Form1.Image7(i).Left

Next i

For i = 1 To 16 Print #1, Form1.Image7(i).Top

Next i

For i = 1 To 16 Print #1, Form1.Image7(i).Tag

Next i

Print #1, turn

If gamemode = "Professional" Then Print #1, "Professional"

Else

Print #1, "Amateur" End If

Print #1, timerw(0)

Print #1, timerw(1)

Print #1, timerb(0)

Print #1, timerb(1)

Close #1

Me.Hide Form1.Show

Form1.Enabled = True

Form1.Timer2.Enabled = True If gamemode = "Professional" Then

Form1.Timer3.Enabled = True

End If

If overwrite = 7 Then

MsgBox ("File Saved") overwrite = -1

End If

MsgBox ("Start Game") If gamemode <> "Amateur" Then

Form1.Frame1.Visible = True

End If

Else

MsgBox ("Filename already exist") overwrite = MsgBox("Over write existing file?", vbYesNo) =

vbYes And vbNo

If overwrite = 7 Then GoTo over

End If

End If currentsavefile = Text1.Text

savefilelocation = ""

End If End Sub

Private Sub Form_Unload(Cancel As Integer) Form1.Show

Form1.Enabled = True

Form1.Timer5.Enabled = True End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then

Call Command1_Click

End If End Sub

Form3

Private Sub Command1_Click() If Option1(0).Value = True And Option1(1).Value = False

Then

gamemode = "Amateur" Form1.Label10.Caption = "Amateur"

Form1.Image6(9).Visible = True

Form1.Image6(1).Visible = True Form1.Image7(1).Visible = True

Form1.Image7(9).Visible = True

time = 1 Form1.Timer1.Enabled = True

Me.Hide

Form1.Enabled = True Form1.Show

Else

If Option1(0).Value = False And Option1(1).Value = True Then

gamemode = "Professional"

time = 0 Form1.Label10.Caption = "Professional"

Do While (settime < 1 Or settime > 90)

settime = Val(InputBox("Set Time Lapse:", "Set Time"))

Loop

timerw(0) = 0: timerw(1) = settime

timerb(0) = 0: timerb(1) = settime For i = 1 To 16

Form1.Image6(i).Visible = True

Form1.Image7(i).Visible = True Next i

Form1.Timer1.Enabled = True

Me.Hide Form1.Enabled = True

Form1.Show

End If End If

End Sub

Private Sub Form_Unload(Cancel As Integer)

Form1.Show

Form1.Enabled = True End Sub

Page 128: PC-Based Electronic Chess Board Game

Appendix D D-79

Private Sub Option1_KeyPress(Index As Integer, KeyAscii

As Integer) If KeyAscii = 13 Then

Call Command1_Click

End If End Sub

Module1

Public Declare Function Inp Lib "inpout32.dll" Alias "Inp32"

(ByVal PortAddress As Integer) As Integer Public Declare Sub Out Lib "inpout32.dll" Alias "Out32"

(ByVal PortAddress As Integer, ByVal Value As Integer)

Public Declare Function Beep Lib "kernel32" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long

Public IMBcnt As Integer, gamemode As String, time As

Integer, settime As Integer, timerw(1) As Integer, timerb(1) As Integer, savefilelocation As String, currentsavefile As

String, turn As String, overwrite As Integer

Page 129: PC-Based Electronic Chess Board Game

APPENDIX E

User’s Manual

Page 130: PC-Based Electronic Chess Board Game

Appendix E E-1

Appendix E – User’s Manual

In regards with the user’s safety and for the project to function properly, the

following must be properly followed.

Connect 5v power

supply of the chess

board

Ikabit ang 5v power

supply sa chess

board.

Connect Parallel

port from the chess

board to the PC.

Ikabit ang Parallel

port mula sa chess

board papuntang

PC.

Check the

communication

between the board

and the PC by

running the test

program.

Download the

DLL.

Tingnan kung ang

communication ng

board at PC ay

gumagana sa

pamamagitan ng

pagbukas ng test

program.

DC Source

Parallel Port

Page 131: PC-Based Electronic Chess Board Game

Appendix E E-2

Run the simulator

program.

Patakbuhin ang

simulator program.

Click the file >new

game to start a new

game.

i-click ang file >

new game para

makapag simula ng

bagong laro.

Select game mode.

(“Amateur or

Professional”)

Pumili kung anong

mode ang gagmitin.

(“Amateur o

Professional”)

Page 132: PC-Based Electronic Chess Board Game

Appendix E E-3

Amateur

Place the pieces on

the chess board

according to what

is shown on the

screen.

Ilagay ang mga

piyesa sa chess

board ayon sa

ipinpakita sa screen

Next column will

appear if the

pieces on the

board occupy the

square where the

image on the

screen is located.

Ipapakita sa

susunod na column

ang piyesa n dapat

ilagay sa board na

makikita sa screen.

After all of the

pieces were placed

on there respective

positions the

program prompts

you to save the

game.

Type the filename

for the save game.

Pagkatapos

mailagay lahat ng

piyesa sa tamang

posisyon ay

kelangan munang

I’save ang laro bago

ito mag simula.

I’type ang nais na

pangalan ng laro.

Page 133: PC-Based Electronic Chess Board Game

Appendix E E-4

Set time, then click

OK.

I-set ang time tapos

i-click ang OK

button.

After setting the

time, all the pieces

must be placed in

their respective

positions.

Pagkatapos ma-set

ang oras,

kealangang ipwesto

ang lahat ng pyesa

sa tamang

posisyon.

After saving the

game, it

automatically starts

the game.

Ang laro ay mag-

sisimula

pagkatapos itong

mai-save.

Professional

Page 134: PC-Based Electronic Chess Board Game

Appendix E E-5

After all the pieces

were placed in their

proper positions,

the program

prompts the user to

save the game.

Type the filename

for the save game.

Pagkatapos i-set

ang time kailangan

munang i-save ang

laro bago ito mag

simula.

I’type ang nais na

pangalan ng laro.

The game will start

automatically, after

saving the game.

White timer will

also run.

Ang laro ay

magsisimula agad

pagkatapos itong

mai-save. Ang oras

ng puting player ay

kusa ring aandar.

How to move the

piece:

The piece must be

lifted atleast 1 inch

from the board.

On placing the

piece, the magnets

should be aligned

to the sensor.

Sa pag tira ng

pyesa kelangang

nakaangat ito ng 1

inch mula sa board.

At sa pag lapag ay

kelangan naka align

sa sensor.

Page 135: PC-Based Electronic Chess Board Game

Appendix E E-6

To capture a piece,

the piece of the

player that is on his

turn must be (1)

lifted then the (2)

opponent’s piece

must be lifted

before (3) placing

the capturing piece.

Sa pag-capture ng

piece ng kalaban,

kailangan munang

i-angat ang

huhuling piece

bago i-angat ang

piece ng kalaban

During castling,(1

and 2) the king

must be first moved

before (3 and 4)

moving the rook in

place.

Kapag magka-

castling, kailangan

munang i-move ang

king bago ang rook.

When a (1) pawn

has been promoted,

the program

temporarily pauses

and (2) prompts the

users to select a

piece to replace the

promoted pawn.

Then (3) replace

the pawn with the

selected piece on

the board.

Before (4) clicking

the “OK” button.

Then the game will

resume

automatically.

Kapag ang pawn ay

na-promote na, ang

program ay

panandaliang

hihinto at papipiliin

kung anong piece

ang ipapalit sa na-

promote na piece,

kailangan munang

palitan ang piece sa

board bago i-click

ang “OK” na

button.

Page 136: PC-Based Electronic Chess Board Game

APPENDIX F

Projects Photos/Screenshots

Page 137: PC-Based Electronic Chess Board Game

Appendix F F-1

Appendix F – Project Photos/Screenshots

Page 138: PC-Based Electronic Chess Board Game

Appendix F F-2

Page 139: PC-Based Electronic Chess Board Game

Appendix F F-3

Page 140: PC-Based Electronic Chess Board Game

Appendix F F-4

Page 141: PC-Based Electronic Chess Board Game

Appendix F F-5

Page 142: PC-Based Electronic Chess Board Game

Appendix F F-6

Page 143: PC-Based Electronic Chess Board Game

Resource Person

Name: Joel Jimenez

Position: Instructor

School: STI College-Makati

Name: Ronald Hermida

Position: Student

School: STI College-Makati

Page 144: PC-Based Electronic Chess Board Game

Technical Vitae

Name: Saliente, Peter John C.

Address: 54 Masias Compound Electrical

RoadPasayCity

Contact no. 09351673225

Email add: [email protected]

PERSONAL DATA

Age : 20

Gender : Male

Date of Birth : December 28, 1989

Civil Status : Single

Religion : Christian

EDUCATIONAL BACKGROUND

Tertiary

Bachelor of Science in Computer Engineering 2006 – 2011

STICollegeMakati

Secondary

BaclaranHigh School (PNHS ANNEX) 2002 – 2006

Page 145: PC-Based Electronic Chess Board Game

Name: Ulama, Bernoullie M.

Address: 118 Central Kalayaan

Bo. Balagbag, PasayCity

Contact no. 09293210043

Email add: [email protected]

PERSONAL DATA

Age : 21

Gender : Male

Date of Birth : August 11, 1989

Civil Status : Single

Religion : Catholic

EDUCATIONAL BACKGROUND

Tertiary

Bachelor of Science in Computer Engineering 2006 – 2011

STICollegeMakati

Secondary

Pasay City South High School 2002 – 2006

Page 146: PC-Based Electronic Chess Board Game

Name: Cuarteros, Ron Jyro L.

Address: B 29 L 33 EP Housing

Western Bicutan, Taguig City

Contact no. 09277236193

Email add: [email protected]

PERSONAL DATA

Age : 22

Gender : Male

Date of Birth : February 25, 1987

Civil Status : Single

Religion : Catholic

EDUCATIONAL BACKGROUND

Tertiary

Bachelor of Science in Computer Engineering 2006 – 2011

STICollegeMakati

Secondary

Saint Patricia Foundation School 2000 – 2004