This week we have continued on the code for the recognition for the pieces. We have been able to recognize a pawn. Also continued the work on making a chess game to be used with the interface for the system. We have also continued on printing and testing that the pieces for the railing system works.
Helge Sondre Ulberg, Oriana Presacan and Ole Henrik Flesaker.
we improved the contour around the pieces so it looks at the 5X5 pixels around it instead of 1X1. We also managed to make the red colour used for the contour appear only around the chess pieces, and not on the other parts where we have blue. After doing that, we were able to recognize the pawns by counting the amount of pixels inside the contour. We can also see the other pieces, but it is hard to differentiate them because of their similar size.
Picture of a pawn being recognized
This is the code for both the contour and the test part for recognition.
if (useContour)
{
int blue = 0;
for (int w = 170; w < texture.height – 170; w++)
{
for (int q = 220; q < texture.width – 220; q++)
{
if (aArray[w, q].b == 1)
{
blue++;
if (aArray[w – 1, q].b != 1 && aArray[w – 2, q].b != 1 && aArray[w – 3, q].b != 1 && aArray[w – 4, q].b != 1 && aArray[w – 5, q].b != 1)
{
aArray[w – 1, q] = new Color(1, 0, 0, 1);
aArray[w – 2, q] = new Color(1, 0, 0, 1);
aArray[w – 3, q] = new Color(1, 0, 0, 1);
}
if (aArray[w + 1, q].b != 1 && aArray[w + 2, q].b != 1 && aArray[w + 3, q].b != 1 && aArray[w + 4, q].b != 1 && aArray[w + 5, q].b != 1)
{
aArray[w + 1, q] = new Color(1, 0, 0, 1);
aArray[w + 2, q] = new Color(1, 0, 0, 1);
aArray[w + 3, q] = new Color(1, 0, 0, 1);
}
if (aArray[w, q – 1].b != 1 && aArray[w, q – 2].b != 1 && aArray[w, q – 3].b != 1 && aArray[w, q – 4].b != 1 && aArray[w, q – 5].b != 1)
{
aArray[w, q – 1] = new Color(1, 0, 0, 1);
aArray[w, q – 2] = new Color(1, 0, 0, 1);
aArray[w, q – 3] = new Color(1, 0, 0, 1);
}
if (aArray[w, q + 1].b != 1 && aArray[w, q + 2].b != 1 && aArray[w, q + 3].b != 1 && aArray[w, q + 4].b != 1 && aArray[w, q + 5].b != 1)
{
aArray[w, q + 1] = new Color(1, 0, 0, 1);
aArray[w, q + 2] = new Color(1, 0, 0, 1);
aArray[w, q + 3] = new Color(1, 0, 0, 1);
}
}
}
}
if (blue > 15 && blue < 95)
{
pawnText = true;
}
else
{
pawnText = false;
}
if (blue > 220 && blue < 300)
{
horseText = true;
}
else
{
horseText = false;
}
if (blue > 190 && blue < 220)
{
kingText = true;
}
else
{
kingText = false;
}
if (blue > 95 && blue < 130)
{
queenText = true;
}
else
{
queenText = false;
}
Debug.Log(blue);
Sondre:
Last week I had a quick lecture with Steven in Git and GitHub, since I was gone the following Thursday, I focused on getting more familiar with Git and Windows PowerShell. This week, I have tried to make the highlight for possible moves for the pieces to work, but it still isn’t working properly. In addition, almost all the pieces have their basic rules for movement scripted, as well as basic captures. Special moves like: “En passant”Castling and pawn promotion will be made later. Code for the board highlight
public class BoardHighlights : MonoBehaviour
{
public static BoardHighlights Instance { set; get; }
public GameObject highlightPrefab; //skifta h til H
private List<GameObject> highlights;
private void Start()
{
Instance = this;
highlights = new List<GameObject>();
}
private GameObject GetHighlightObject()
{
GameObject go = highlights.Find (g => !g.activeSelf);
if(go == null)
{
go = Instantiate(highlightPrefab); //skifta h til H
highlights.Add(go);
}
return go;
}
public void HighlightAllowedMoves(bool[,] moves)
{
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
if (moves[i, j])
{
GameObject go = GetHighlightObject();
go.SetActive(true);
go.transform.position = new Vector3(i+0.5f, 0, j+0.5f);
}
}
}
}
public void Hidehighlights()
{
foreach (GameObject go in highlights)
go.SetActive(false);
}
}
Stian Bergstrøm:
For this Week I have finished the design for the railing for the axis system. We have been able to print out atleast one of each part wich are ready to be tested to se if they work before we put everything togheter. From the last timet he pulleys have been redesigned and printed on new to see if they work as intended this time. The slider piece was made with a little to much tolerance and have too much wiggle room. Also added a piece to hold the elctromagnet and the motor brackets for the stepper motor.