proyecto de investigacion

17
Universidad Insurgentes Inteligencia Artificial 2 Proyecto 2 8-Puzzle Alejandro Salazar Guerrero febrero 2014 1

description

proyecto de investigacion

Transcript of proyecto de investigacion

Page 1: proyecto de investigacion

Universidad InsurgentesInteligencia Artificial 2

Proyecto 28-Puzzle

Alejandro Salazar Guerrero

febrero 2014

1

Page 2: proyecto de investigacion

Contenido

I. Objetivo

II. Introducción

III. Desarrollo

IV. Conclusiones

V. Referencias

2

Page 3: proyecto de investigacion

I. Objetivo

El objetivo de este proyecto consiste en la implementación del algoritmo para el juego del 8-

Puzzle en VisualBasic.Net.

3

Page 4: proyecto de investigacion

II. Introducción

El lenguaje Visual Basic .Net es uno de los más modernos e importantes actualmente y permite la

programación orientada a objetos en ambiente gráfico, con lo que una primera implementación del

algoritmo en este entorno, servirá de base para una migración posterior a Visual Prolog, con mayores

características de los lenguajes de quinta generación.

III. Desarrollo

La primera parte del proyecto, consiste en que el programa genere por medio de números aleatorios, los números en las posiciones que conforman el estado inicial, posteriormente, el jugador va tratando de colocarlos en orden secuencial hasta terminar los 8. Al final, el programa indica que el jugador ha ganado.

En una segunda implementación, el programa deberá buscar la solución de manera automática, optimizando los pasos de acuerdo al algoritmo correspondiente y optimizando la solución por medio de decisiones adecuadas.

La tercera versión consistiría en que el programa muestre una serie de estados finales, de los cuales el usuario seleccionará uno y el programa lo resolverá o le indicará que no existe la solución.

4

Page 5: proyecto de investigacion

Código del programa.

Public Class Form1 Dim x As Integer Dim y As Integer

Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click

Dim Random As New Random() Randomize() Button1.Text = Random.Next(0, 9) Button2.Text = Random.Next(0, 9) While (Button2.Text = Button1.Text) Button2.Text = Random.Next(0, 9) End While Button3.Text = Random.Next(0, 9) While (Button3.Text = Button1.Text Or Button3.Text = Button2.Text) Button3.Text = Random.Next(0, 9) End While Button4.Text = Random.Next(0, 9) While (Button4.Text = Button1.Text Or Button4.Text = Button2.Text Or Button4.Text = Button3.Text)

5

Page 6: proyecto de investigacion

Button4.Text = Random.Next(0, 9) End While Button5.Text = Random.Next(0, 9) While (Button5.Text = Button1.Text Or Button5.Text = Button2.Text Or Button5.Text = Button3.Text Or Button5.Text = Button4.Text) Button5.Text = Random.Next(0, 8) End While Button6.Text = Random.Next(0, 9) While (Button6.Text = Button1.Text Or Button6.Text = Button2.Text Or Button6.Text = Button3.Text Or Button6.Text = Button4.Text Or Button6.Text = Button5.Text) Button6.Text = Random.Next(0, 8) End While Button7.Text = Random.Next(0, 9) While (Button7.Text = Button1.Text Or Button7.Text = Button2.Text Or Button7.Text = Button3.Text Or Button7.Text = Button4.Text Or Button7.Text = Button5.Text Or Button7.Text = Button6.Text) Button7.Text = Random.Next(0, 8) End While Button8.Text = Random.Next(0, 9) While (Button8.Text = Button1.Text Or Button8.Text = Button2.Text Or Button8.Text = Button3.Text Or Button8.Text = Button4.Text Or Button8.Text = Button5.Text Or Button8.Text = Button6.Text Or Button8.Text = Button7.Text) Button8.Text = Random.Next(0, 8) End While Button9.Text = Random.Next(0, 9) While (Button9.Text = Button1.Text Or Button9.Text = Button2.Text Or Button9.Text = Button3.Text Or Button9.Text = Button4.Text Or Button9.Text = Button5.Text Or Button9.Text = Button6.Text Or Button9.Text = Button7.Text Or Button9.Text = Button8.Text) Button9.Text = Random.Next(0, 9) End While If Button1.Text = 0 Then Button1.Text = "" x = Me.Button1.Location.X y = Me.Button1.Location.Y Else If Button2.Text = 0 Then Button2.Text = "" x = Me.Button2.Location.X y = Me.Button2.Location.Y Else If Button3.Text = 0 Then Button3.Text = "" x = Me.Button3.Location.X y = Me.Button3.Location.Y Else If Button4.Text = 0 Then Button4.Text = "" x = Me.Button4.Location.X

6

Page 7: proyecto de investigacion

y = Me.Button4.Location.Y Else If Button5.Text = 0 Then Button5.Text = "" x = Me.Button5.Location.X y = Me.Button5.Location.Y Else If Button6.Text = 0 Then Button6.Text = "" x = Me.Button6.Location.X y = Me.Button6.Location.Y Else If Button7.Text = 0 Then Button7.Text = "" x = Me.Button7.Location.X y = Me.Button7.Location.Y Else If Button8.Text = 0 Then Button8.Text = "" x = Me.Button8.Location.X y = Me.Button8.Location.Y Else If Button9.Text = 0 Then Button9.Text = "" x = Me.Button9.Location.X y = Me.Button9.Location.Y End If End If End If End If End If End If End If End If End If End Sub

Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click End End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click If x = 215 And y = 29 Then Button3.Text = Button6.Text

7

Page 8: proyecto de investigacion

Button6.Text = "" x = Me.Button6.Location.X y = Me.Button6.Location.Y Else If x = 121 And y = 109 Then Button5.Text = Button6.Text Button6.Text = "" x = Me.Button6.Location.X y = Me.Button6.Location.Y Else If x = 215 And y = 189 Then Button9.Text = Button6.Text Button6.Text = "" x = Me.Button6.Location.X y = Me.Button6.Location.Y End If End If End If Call PROC1() End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If x = 121 And y = 29 Then Button2.Text = Button1.Text Button1.Text = "" x = Me.Button1.Location.X y = Me.Button1.Location.Y Else If x = 29 And y = 109 Then Button4.Text = Button1.Text Button1.Text = "" x = Me.Button1.Location.X y = Me.Button1.Location.Y End If End If Call PROC1() End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click If x = 29 And y = 29 Then Button1.Text = Button2.Text Button2.Text = "" x = Me.Button2.Location.X y = Me.Button2.Location.Y

8

Page 9: proyecto de investigacion

Else If x = 121 And y = 109 Then Button5.Text = Button2.Text Button2.Text = "" x = Me.Button2.Location.X y = Me.Button2.Location.Y Else If x = 215 And y = 29 Then Button3.Text = Button2.Text Button2.Text = "" x = Me.Button2.Location.X y = Me.Button2.Location.Y End If End If End If Call PROC1() End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click If x = 121 And y = 29 Then Button2.Text = Button3.Text Button3.Text = "" x = Me.Button3.Location.X y = Me.Button3.Location.Y Else If x = 215 And y = 109 Then Button6.Text = Button3.Text Button3.Text = "" x = Me.Button3.Location.X y = Me.Button3.Location.Y End If End If Call PROC1() End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click If x = 29 And y = 29 Then Button1.Text = Button4.Text Button4.Text = "" x = Me.Button4.Location.X y = Me.Button4.Location.Y Else If x = 121 And y = 109 Then Button5.Text = Button4.Text

9

Page 10: proyecto de investigacion

Button4.Text = "" x = Me.Button4.Location.X y = Me.Button4.Location.Y Else If x = 29 And y = 189 Then Button7.Text = Button4.Text Button4.Text = "" x = Me.Button4.Location.X y = Me.Button4.Location.Y End If End If End If Call PROC1() End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click If x = 121 And y = 29 Then Button2.Text = Button5.Text Button5.Text = "" x = Me.Button5.Location.X y = Me.Button5.Location.Y Else If x = 29 And y = 109 Then Button4.Text = Button5.Text Button5.Text = "" x = Me.Button5.Location.X y = Me.Button5.Location.Y Else If x = 215 And y = 109 Then Button6.Text = Button5.Text Button5.Text = "" x = Me.Button5.Location.X y = Me.Button5.Location.Y Else If x = 121 And y = 189 Then Button8.Text = Button5.Text Button5.Text = "" x = Me.Button5.Location.X y = Me.Button5.Location.Y End If End If End If End If Call PROC1() End Sub

10

Page 11: proyecto de investigacion

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click If x = 29 And y = 109 Then Button4.Text = Button7.Text Button7.Text = "" x = Me.Button7.Location.X y = Me.Button7.Location.Y Else If x = 121 And y = 189 Then Button8.Text = Button7.Text Button7.Text = "" x = Me.Button7.Location.X y = Me.Button7.Location.Y End If End If Call PROC1() End Sub

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click If x = 121 And y = 109 Then Button5.Text = Button8.Text Button8.Text = "" x = Me.Button8.Location.X y = Me.Button8.Location.Y Else If x = 29 And y = 189 Then Button7.Text = Button8.Text Button8.Text = "" x = Me.Button8.Location.X y = Me.Button8.Location.Y Else If x = 215 And y = 189 Then Button9.Text = Button8.Text Button8.Text = "" x = Me.Button8.Location.X y = Me.Button8.Location.Y End If End If End If Call PROC1() End Sub

Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click

11

Page 12: proyecto de investigacion

If x = 215 And y = 109 Then Button6.Text = Button9.Text Button9.Text = "" x = Me.Button9.Location.X y = Me.Button9.Location.Y Else If x = 121 And y = 189 Then Button8.Text = Button9.Text Button9.Text = "" x = Me.Button9.Location.X y = Me.Button9.Location.Y End If End If Call PROC1() End Sub Sub PROC1() If Button1.Text = "1" And Button2.Text = "2" And Button3.Text = "3" And Button4.Text = "4" And Button5.Text = "5" And Button6.Text = "6" And Button7.Text = "7" And Button8.Text = "8" Then MsgBox("GANASTE!!!!!") End If End Sub

End Class

Ejecución del programa

12

Page 13: proyecto de investigacion

El programa lo puedes bajar en el siguiente enlace: programa 8-Puzzle

13

Page 14: proyecto de investigacion

IV. Conclusiones

La experiencia de programar los algoritmos basados en juegos permite desarrollar habilidades de

investigación, experimentación, análisis y desarrollo que es una fuente de motivación para adentrarse

en el conocimiento del lenguaje y de las herramientas avanzadas que contiene en las librerías.

14

Page 15: proyecto de investigacion

V. Referencias

Programación Fácil

8-Puzzle

15

Page 16: proyecto de investigacion

16