Simulando Posición de un Ajedrez en C

Publicado por Nick
hace 8 años

<p>Haciendo uso de las posiciones de alguna localidad en la programación, valiendonos de arreglos matriciales simularemos el tablero de un Ajedrez con el orden adecuado de sus piezas, para ello utilizaremos la letra Inicial de cada Pieza:</p><p>T= Torre <br />A= Alfil</p><p>P=Peon</p><p>M=Reina<br />R=Rey</p><p>C= Caballo</p><p><br /></p><p style="text-align:center;"><span style="font-weight:bold;">Tablero de Ajedrez </span></p><p style="text-align:center;"><img src="http://1.bp.blogspot.com/-WJi126Aya_Y/Ut7Q54O5DDI/AAAAAAAAG34/7yR2Kt06bSw/s1600/tablero+y+ubicacion.gif" alt="tablero+y+ubicacion.gif" /><br /></p><p><br /></p><p><span style="font-weight:bold;">Programa escrito en lenguaje C:</span></p><pre><span style="font-weight:bold;">#include <stdio.h><br /></span><span style="font-weight:bold;">#include <stdlib.h></span><span style="font-weight:bold;"><br /></span><span style="font-weight:bold;">int main(int argc, char *argv[])<br /></span><span style="font-weight:bold;">{</span><span style="font-weight:bold;"><br /></span><span style="font-weight:bold;">    int x,y;<br /></span><span style="font-weight:bold;">   <br /></span><span style="font-weight:bold;">    for (x=0;x<8;x++)<br /></span><span style="font-weight:bold;">    {<br /></span><span style="font-weight:bold;">        for (y=0;y<8;y++)<br /></span><span style="font-weight:bold;">        {<br /></span><span style="font-weight:bold;">            //peones<br /></span><span style="font-weight:bold;">            if (x==1 || x==6)<br /></span><span style="font-weight:bold;">            {<br /></span><span style="font-weight:bold;">             printf("P");<br /></span><span style="font-weight:bold;">            }<br /></span><span style="font-weight:bold;">            //torres<br /></span><span style="font-weight:bold;">            else if ((x==0 && y==0) ||<br /></span><span style="font-weight:bold;">                    (x==7 && y==0) ||<br /></span><span style="font-weight:bold;">                    (x==0 && y==7) ||<br /></span><span style="font-weight:bold;">                    (x==7 && y==7)<br /></span><span style="font-weight:bold;">                    )<br /></span><span style="font-weight:bold;">            {<br /></span><span style="font-weight:bold;">             printf("T");<br /></span><span style="font-weight:bold;">            }<br /></span><span style="font-weight:bold;">            //caballos<br /></span><span style="font-weight:bold;">            else if ((x==0 && y==1) ||<br /></span><span style="font-weight:bold;">                    (x==7 && y==1) ||<br /></span><span style="font-weight:bold;">                    (x==0 && y==6) ||<br /></span><span style="font-weight:bold;">                    (x==7 && y==6)<br /></span><span style="font-weight:bold;">                    )<br /></span><span style="font-weight:bold;">            {<br /></span><span style="font-weight:bold;">             printf("C");<br /></span><span style="font-weight:bold;">            }<br /></span><span style="font-weight:bold;">            //alfiles<br /></span><span style="font-weight:bold;">            else if ((x==0 && y==2) ||<br /></span><span style="font-weight:bold;">                    (x==7 && y==2) ||<br /></span><span style="font-weight:bold;">                    (x==0 && y==5) ||<br /></span><span style="font-weight:bold;">                    (x==7 && y==5)<br /></span><span style="font-weight:bold;">                    )<br /></span><span style="font-weight:bold;">            {<br /></span><span style="font-weight:bold;">             printf("A");<br /></span><span style="font-weight:bold;">            }<br /></span><span style="font-weight:bold;">            //reina<br /></span><span style="font-weight:bold;">            else if ((x==0 && y==3) ||<br /></span><span style="font-weight:bold;">                    (x==7 && y==3)<br /></span><span style="font-weight:bold;">                    )<br /></span><span style="font-weight:bold;">            {<br /></span><span style="font-weight:bold;">             printf("M");<br /></span><span style="font-weight:bold;">            }<br /></span><span style="font-weight:bold;">            //rey<br /></span><span style="font-weight:bold;">            else if ((x==0 && y==4) ||<br /></span><span style="font-weight:bold;">                    (x==7 && y==4)<br /></span><span style="font-weight:bold;">                    )<br /></span><span style="font-weight:bold;">            {<br /></span><span style="font-weight:bold;">             printf("R");<br /></span><span style="font-weight:bold;">            }<br /></span><span style="font-weight:bold;">            else<br /></span><span style="font-weight:bold;">            {<br /></span><span style="font-weight:bold;">                printf(" ");<br /></span><span style="font-weight:bold;">            }<br /></span><span style="font-weight:bold;">        }<br /></span><span style="font-weight:bold;">        printf("\n");<br /></span><span style="font-weight:bold;">    }<br /></span><span style="font-weight:bold;">   <br /></span><span style="font-weight:bold;">       <br /></span><span style="font-weight:bold;">    return 0;</span><span style="font-weight:bold;"><br /></span><span style="font-weight:bold;">}</span></pre><p></p><p><span style="font-weight:bold;"><br /></span></p><pre class="prettyprint prettyprinted"><span style="font-weight:bold;text-align:justify;">Programa Corriendo:</span><br /></pre><div class="MsoNormal" style="text-align:justify;"><span style="font-weight:bold;"><br /></span></div><div class="MsoNormal" style="text-align:center;"><span style="font-weight:bold;"><br /></span></div><div class="MsoNormal" style="text-align:center;"><img src="http://s15.postimg.org/dr2m3cpqz/yyyyy.jpg" alt="yyyyy.jpg" /><br /></div>

c matriz array ajedrez