Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                		<!--
		<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
		-->
	<h2>I moved this project to Github for a real chess game.</h2>
	<a href="https://github.com/guneysus/chess.js">Repo</a>
	<!-- <a href="https://guneysus.github.io/chess-js/">Demo</a> -->

	<p></p>
<hr />
		<script src="js/helpers.js"></script>
		<script src="js/objects.js"></script>
		<script src="js/index.js"></script>
		<div id="wrapper">
				<form id="tasSecim">
				<!-- From http://en.wikipedia.org/wiki/Chess_symbols_in_Unicode -->
				<input type="radio" name="tas" value="Piyon(1)"><span>♙</span>
				<input type="radio" name="tas" value="Kale(1)"><span>♖</span>
				<input type="radio" name="tas" value="At(1)"><span>♘</span>
				<input type="radio" name="tas" value="Fil(1)"><span>♗</span>
				<input type="radio" name="tas" value="Vezir(1)" checked><span>♕</span>
				<input type="radio" name="tas" value="Sah(1)"><span>♔</span>
				<hr>
				<input type="radio" name="tas" value="Piyon()"><span>♟</span>
				<input type="radio" name="tas" value="Kale()"><span>♜</span>
				<input type="radio" name="tas" value="At()"><span>♞</span>
				<input type="radio" name="tas" value="Fil()"><span>♝</span>
				<input type="radio" name="tas" value="Vezir()"><span>♛</span>
				<input type="radio" name="tas" value="Sah()"><span>♚</span>				
			</form>
			<div id="alan">


			</div>
		</div>
              
            
!

CSS

              
                $CellWidth: 60px

$Tan: #D2B48C
$UbuntuConsole: rgba(60,0,40, 0.9)

$LightGray: rgba(128, 128, 128, 1.0)
$DarkGray: rgba(32, 32, 32, 1.0) // dark gray

$WhiteTransparent: rgba(255, 255, 255, 0.9)
$BlackTransparent: rgba(0, 0, 0, 0.9)

// https://www.w3schools.com/tags/ref_colorpicker.asp?colorhex=D2B48C
$TanDark: #BDA27E // #A89070 // #937E62 // #7E6C54 //#695A46
$TanLight: #E8DAC6

$TanExtraDark: #695A46
$TanExtraLight: #F6F0E8


$OddBG: $TanDark 
$EvenBG: $TanLight

$OddSelectedBG: 	$TanExtraDark
$EvenSelectedBG:	$TanExtraLight

*
	font-family: Arial, Helvetica, sans-serif	
body
	background-color: $Tan

#tasSecim
	width: 8 * $CellWidth
	margin: 0 auto

#alan
	border: 3px solid rgba(16, 16, 16, 0.60)
	width: 8 * $CellWidth
	height: 8 * $CellWidth
	padding: 0
	margin: -50px auto
	box-shadow: 0px 2px 28px 17px rgba(105,90,70,0.5)
	transform: perspective( 1000px ) rotate3d(1, 0, 0, 40deg) rotate3d(0, 1, 0, 0deg) rotate3d(0, 0, 1, 0deg)
	
	div
		margin: 0
		padding: 0
		height: $CellWidth
	
input[type=button].number
	padding: 0
	margin: 0
	width: $CellWidth
	height: $CellWidth
	text-align: center
	border: 0px 

.moves
	background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAFoEvQfAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3wMbFxkJFLEKXQAAAA1JREFUCNdjKLz5VwcABnoCdAk8TH0AAAAASUVORK5CYII=")

.greendot
	background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJCAYAAADgkQYQAAAAnUlEQVR42mNggAJVVdUoVRWV1UD6DIhWU1MLZEACzMrKykttw3X/BzYb/4+aZg6mrYJ0/gM1zISZkOYQp/8/baM1BraJ0PmvoqISywA0+kB4vzlWRWG9Zv+B1u4FmfQwYaElVkVxcy1AJt0mziSQnbYRutjdFKL3X1FRMQTm+Pkg3wW1QXwX3GoK89005GCAhJOq6kZwOKmqrkMOJwADyXm2Tc33VQAAAABJRU5ErkJggg==") no-repeat center


.reddot, .opponent
	background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJCAMAAADXT/YiAAAAY1BMVEUmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiZrQUF1RUVzRUW4YGDUbGzHZ2dtQ0PJaGj/fX29YmK6YmLlc3N9SUngcXGmdL7+AAAAE3RSTlMAWsxRq8C9XQOlmWbh21SflrGuCL+ygQAAAERJREFUeF5NyEUSgDAAwMBUoLhVcf7/SoaeyGkngNBSK6CqfYjBNtDe+5czFFtWKumurKf/PeOy1gFGf8TTTgBilouCF+lbBVAdEWw6AAAAAElFTkSuQmCC") no-repeat center

.orangedot
	background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJCAYAAADgkQYQAAAAoklEQVR42mNggAINDY0odVWN1UD6DIhWVlMLZEACzMrKyksLvfX+b8w0/H+m3ARMZ3no/ldVVZ0JMyGtKlD//+cuMwxc5K39X0VFJZYBaPSBwyVmWBXtLzT+r6amthdk0sN7DeZYFV2vMQOZdJs4k0B2FvvoYVWU7an3X05OLgTseKDq+SDfbcuG+G5ztjHMd9OQgwESTurqG0HhBJRchxxOALJRiFeLGuZnAAAAAElFTkSuQmCC") no-repeat center

.bluedot
	background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJCAYAAADgkQYQAAAAp0lEQVR42mNggAINDY0oVXWV1UD6DIjWVFMLZEACzKqqqksNw0v+WzTs+G876SqYNgjK/a+mpjYTZkKaSWz9f6fV/zGwQXj5fxUVlVgGVXXVA7Y9p7Aqsu48/l9dXX0vyKSH9nOfYVVkN/P+f6BTbhNnEshOw4gyrIqMQvL/KyoqhoAdD/TFfLDvmveCfWfVtAvsO6Ap05CDARxOQMGNoHACalqHHE4AyV+QhNXOr1MAAAAASUVORK5CYII=") no-repeat center

hr
	border: 1px dashed gray

input[type=button]
	font-size: 50px
	vertical-align: top
	box-shadow: inset 0px 0px 10px 4px rgba(105, 90, 70, 0.15)


input[type=button].odd
	background-color:  $OddBG

input[type=button].odd.selected
	background-color: $OddSelectedBG
	color: black



input[type=button].even
	background-color: $EvenBG

input[type=button].even.selected
	background-color: $EvenSelectedBG
	color: black

input[type=radio] + span
	font-size: 50px
	color: black

.selected_blue
	background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mMovPm3DgAGzALG7XSWygAAAABJRU5ErkJggg==")


.selected_green, .selected
	background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mOY8X/GdAAHKQLHWT/FfgAAAABJRU5ErkJggg==")
              
            
!

JS

              
                // attach the .equals method to Array's prototype to call it on any array
Array.prototype.equals = function (array) {
    /*
     Dizileri eşitliğini kontrol etmek.
     Çünkü [1,1] == [1,1] false dönüyor.
     -----------------------------------------
    KAYNAK: http://stackoverflow.com/a/14853974/1766716
     KULLANIM
        [1, 2, [3, 4]].equals([1, 2, [3, 2]]) === false;
        [1, "2,3"].equals([1, 2, 3]) === false;
        [1, 2, [3, 4]].equals([1, 2, [3, 4]]) === true;
        [1, 2, 1, 2].equals([1, 2, 1, 2]) === true;
    */
    // if the other array is a falsy value, return
    if (!array)
        return false;

    // compare lengths - can save a lot of time 
    if (this.length != array.length)
        return false;

    for (var i = 0, l=this.length; i < l; i++) {
        // Check if we have nested arrays
        if (this[i] instanceof Array && array[i] instanceof Array) {
            // recurse into the nested arrays
            if (!this[i].equals(array[i]))
                return false;       
        }           
        else if (this[i] != array[i]) { 
            // Warning - two different object instances will never be equal: {x:20} != {x:20}
            return false;   
        }           
    }       
    return true;
}  


// OBJECTS >>

function getCell(i, j){
		return cells[ i* 8 + j];
}
function Cell(i, j) {
    this.i = i;
    this.j = j;
    this.id = 'cell' + this.i + this.j;

    this.oddEven = ((this.i + this.j) % 2 == 0 ? 'odd' : 'even');
    this.dom = function() {
        return $('#' + this.id);
    };

    this.highlight = function() {
        $(this.dom()).addClass( classMoves );
    };
    this.clean = function() {
        $(this.dom()).removeClass( classMoves  );
    };
};


var Tas = function(ad, renk) {
    this.ad = ad;
    this.renk = (renk === undefined || [0, 1].indexOf(renk) == -1 ? 0 : renk); // 0 : (Default) Siyah | 1 : Beyaz
    this.movesTo = [];
    this.isvalid = function(i, j, x, y) {
        return ( ! [i, j].equals([x, y])) && (0 <= i < 8) && (0 <= j < 8)
    }
    this.moves = function(x, y) {
				this.movesTo = [];
        this.findMoves(x, y);
        this.movesHightlight();
    };


    this.findMoves = function() {
        alert('YAKINDA...');
    };

    this.movesHightlight = function() {
        this.movesTo.forEach(function(cell, index) {
            cell.highlight()
        });
    }
};

var Piyon = function(renk) {
    this.adet = 8;
    Tas.call(this, 'Piyon', renk)
    this.findMoves = function(x, y) {
        var moveY = (this.renk == 1 ? +1 : -1); // Beyaz ise + yön, siyah ise - yön.
        x += moveY;
        switch (x) { // satırdaysa bir şey dönme.
            case 8:
                this.movesTo = [];
                break;
            default:
                this.movesTo.push(new Cell(x, y));
                break;
        };
    };
};


var Kale = function(renk) {
    this.adet = 2;
    Tas.call(this, 'Kale', renk);

    this.findMoves = function(x, y) {
        for (var i = 0; i <= 7; i++) {
            if (this.isvalid(i, y, x, y)) {;
                this.movesTo.push(new Cell(i, y));
            }
        }
        for (var j = 0; j <= 7; j++) {
            if (this.isvalid(x, j, x, y)) {;
                this.movesTo.push(new Cell(x, j));
            }
        }
    }

};

var Fil = function(renk) {
    this.adet = 2;
    Tas.call(this, 'Fil', renk);

    this.findMoves = function(x, y) {
        for (i = x, j = y; i <= 7, j <= 7; i++, j++) {
            if (this.isvalid(i, j, x, y)) {;
                this.movesTo.push(new Cell(i, j))
            }
        } // (I. bölge) SOLA YUKARI

        for (i = x, j = y; i <= 7, j >= 0; i++, j--) {
            if (this.isvalid(i, j, x, y)) {;
                this.movesTo.push(new Cell(i, j))
            }
        } // (II. bölge) SAĞA YUKARI

        for (i = x, j = y; i >= 0, j >= 0; i--, j--) {
            if (this.isvalid(i, j, x, y)) {;
                this.movesTo.push(new Cell(i, j));
            }
        } // (II. bölge) SAĞA AŞAĞI}

        for (i = x, j = y; i >= 0, j <= 7; i--, j++) {
            if (this.isvalid(i, j, x, y)) {;
                this.movesTo.push(new Cell(i, j));
            }
        } // (IV. bölge) SOLA AŞAĞI}

    }
}
var At = function(renk) {
    this.adet = 2;
    Tas.call(this, 'At', renk)
    this.findMoves = function(i, j){
    	this.movesTo.push( new Cell( i+2, j+1));
    	this.movesTo.push( new Cell( i+2, j-1));

    	this.movesTo.push( new Cell( i+1, j+2));
    	this.movesTo.push( new Cell( i+1, j-2));

    	this.movesTo.push( new Cell( i-1, j+2));
    	this.movesTo.push( new Cell( i-1, j-2));

    	this.movesTo.push( new Cell( i-2, j+1));
    	this.movesTo.push( new Cell( i-2, j-1));


    }
}
var Sah = function(renk) {
    this.adet = 1;
    Tas.call(this, 'Şah', renk);
    this.findMoves = function(i, j) {
        this.movesTo.push(new Cell(i - 1, j - 1))
        this.movesTo.push(new Cell(i - 1, j))
        this.movesTo.push(new Cell(i - 1, j + 1))
        this.movesTo.push(new Cell(i, j - 1))
        // this.movesTo.push ( new Cell (i, j) )	
        this.movesTo.push(new Cell(i, j + 1))
        this.movesTo.push(new Cell(i + 1, j + 1))
        this.movesTo.push(new Cell(i + 1, j))
        this.movesTo.push(new Cell(i + 1, j - 1))
    }
}
var Vezir = function(renk) {
    this.adet = 1;
    Tas.call(this, 'Vezir', renk);
    this.findMoves = function(x, y) {

        // Fil'in hareketleri >>
        for (i = x, j = y; i <= 7, j <= 7; i++, j++) {
            if (this.isvalid(i, j, x, y)) {;
                this.movesTo.push(new Cell(i, j))
            }
        } // (I. bölge) SOLA YUKARI

        for (i = x, j = y; i <= 7, j >= 0; i++, j--) {
            if (this.isvalid(i, j, x, y)) {;
                this.movesTo.push(new Cell(i, j))
            }
        } // (II. bölge) SAĞA YUKARI

        for (i = x, j = y; i >= 0, j >= 0; i--, j--) {
            if (this.isvalid(i, j, x, y)) {;
                this.movesTo.push(new Cell(i, j));
            }
        } // (II. bölge) SAĞA AŞAĞI}

        for (i = x, j = y; i >= 0, j <= 7; i--, j++) {
            if (this.isvalid(i, j, x, y)) {;
                this.movesTo.push(new Cell(i, j));
            }
        } // (IV. bölge) SOLA AŞAĞI}
        // Fil'in hareketleri <<

        // Kale'nin hareketleri >>
			
       for (var i = 0; i <= 7; i++) {
            if (this.isvalid(i, y, x, y)) {;
                this.movesTo.push(new Cell(i, y));
            }
        }

      for (var j = 0; j <= 7; j++) {
            if (this.isvalid(x, j, x, y)) {;
                this.movesTo.push(new Cell(x, j));
            }
        }
            // Kale'nin hareketleri <<
    }
}

var Taslar = [Piyon, Kale, Fil, At, Sah, Vezir];
var taslar = [];
[0, 1].forEach(function(R) { // Renk
    Taslar.forEach(function(T) { // Tas
        for (var i = 0; i < new T().adet; i++) {
            // console.log(T);
            taslar.push(new T(R));
        };
    });
});
// OBJECTS <<

var i = 0;
var selectedCell;
var selectedCellID;

var selectedPiece;
var selectedPieceText;

var cells = [];
var highlightedCells = [];
var classSelected = 'selected';
var classMoves = 'moves';


function vurgula() {
    db = [cells[0], cells[1], cells[2], cells[5]];

    db.forEach(function(cell, index) {
        cell.highlight();
    });
}

function refresh() {
    temizle();
    selectedPiece = $('input[name=tas]:checked').val();
    selectedPieceText = $('input[name="tas"]:checked + span')[0].innerText;
    var ij = selectedCellID.split('cell')[1]; // ["#", "44"]
    var i = parseInt(ij[0]);
    var j = parseInt(ij[1]);
    eval('new ' + selectedPiece).moves(i, j);
    with($(selectedCell)) {
        removeClass(classSelected);
        val('');
    };

    selectedCell = selectedCellID;

    with($(selectedCellID)) {
        addClass(classSelected);
        val(selectedPieceText);
    }
}

function temizle() {
    cells.forEach(function(cell, index) {
        cell.clean();
    });
}

function butonUret() {
    cells.forEach(function(cell, index) {
        var buton = $(document.createElement('input'));
        with(buton) {
            attr('type', 'button');
            attr('id', cell.id);
            attr('class', ['number', cell.oddEven].join(' '));
            appendTo($("#row" + cell.i));
        }

    });

    // addCellEvents();
    // Add events to buttons
    $("input[type=button]").click(
        function() {
            selectedCellID = '#' + this.id;
            refresh();


        }
    );
}

window.addEventListener('load', function() {
    for (var i = 7; i >= 0; i--) {
        var d = $(document.createElement('div'));
        d.attr('id', 'row' + i);
        d.appendTo($('#alan'));
        for (var j = 7; j >= 0; j--) {
            //butonOlustur(i, j);
            cells.push(new Cell(i, j));
        }
    }

    butonUret();

    $('input[name="tas"]').click(refresh);

    selectedCellID = '#cell22';
    refresh();
});
              
            
!
999px

Console