0

I have 64 divs created dynamically for a checker game. When I jump a checker, I need to be able to delete the jumped checker. How would I track the checkers to be able to delete a jumped checker? All of the divs and images have ids. Since I'm using the Angular cdkDragDrop, event.target.id and event.target.value are not an option. I was thinking of taking the event.clientX and the event.clientY values subtracting the height of the square in both directions and trying to delete the div. I'm stuck. Any help would be appreciated.

Here's the HTML:

<div class="checkerboard-wrapper" cdkDropListGroup>
    <div #square *ngFor="let item of items;let i=index">
        <div id={{item.squareId}} class={{item.class}} cdkDropList [cdkDropListData]="item"
            (cdkDropListDropped)="drop($event)" (pointerdown)="getId($event, i)">
            <div *ngIf="newGame" class="images" (pointerdown)="grabChecker($event, i)"
                (pointerup)="placeChecker($event,id)" (cdkDragEnded)="onDragEnded($event)" cdkDrag>
                <div *cdkDragPlaceholder></div>
                <img appHide loading="lazy" *ngIf="item.img" id={{i}} class="checkerImg" src={{item.img}} />
            </div>
        </div>
    </div>
</div>

This is my ts code:

import { AfterViewInit, Component, OnInit, Input, ViewChildren, QueryList, Renderer2 } from '@angular/core';
import { CdkDragDrop, CdkDragEnd, moveItemInArray, transferArrayItem } from '@angular/cdk/drag-drop';
import { BreakpointState } from '@angular/cdk/layout';
import { HideDirective } from '../../directives/hide.directive';

import { SharedService } from '../../services/shared.service';
import { ScreenService } from '../../services/screen.service';

@Component({
  selector: 'app-checkerboard',
  templateUrl: './checkerboard.component.html',
  styleUrls: ['./checkerboard.component.css'],

})
export class CheckerboardComponent implements OnInit, AfterViewInit {

  isBelowLg: boolean = false;
  disabled: boolean = false;
  newGame: boolean = false;
  currentIndex;
  previousIndex;
  imgId: string;
  @ViewChildren(HideDirective) hideDirectives!: QueryList<HideDirective>;
@ViewChildren('square') squares: QueryList<ElementRef>
  xPointerGrabPosition: number;
  yPointerGrabPosition: number;
  xPointerReleasePosition: number;
  yPointerReleasePosition: number;
  items: Array<any> = [
    { squareId: '1-1', id: '1', class: 'square checkerboard-square-red', img: '' },
    { squareId: '1-2', id: '2', class: 'square checkerboard-square-black', img: ' ../../assets/images/beige-checker-piece.svg' },
    { squareId: '1-3', id: '3', class: 'square checkerboard-square-red', img: '' },
    { squareId: '1-4', id: '4', class: 'square checkerboard-square-black', img: ' ../../assets/images/beige-checker-piece.svg' },
    { squareId: '1-5', id: '5', class: 'square checkerboard-square-red', img: '' },
    { squareId: '1-6', id: '6', class: 'square checkerboard-square-black', img: ' ../../assets/images/beige-checker-piece.svg' },
    { squareId: '1-7', id: '7', class: 'square checkerboard-square-red', img: '' },
    { squareId: '1-8', id: '8', class: 'square checkerboard-square-black', img: ' ../../assets/images/beige-checker-piece.svg' },

    { squareId: '2-1', id: '9', class: 'square checkerboard-square-black', img: ' ../../assets/images/beige-checker-piece.svg' },
    { squareId: '2-2', id: '10', class: 'square checkerboard-square-red', img: '' },
    { squareId: '2-3', id: '11', class: 'square checkerboard-square-black', img: ' ../../assets/images/beige-checker-piece.svg' },
    { squareId: '2-4', id: '12', class: 'square checkerboard-square-red', img: '' },
    { squareId: '2-5', id: '13', class: 'square checkerboard-square-black', img: ' ../../assets/images/beige-checker-piece.svg' },
    { squareId: '2-6', id: '14', class: 'square checkerboard-square-red', img: '' },
    { squareId: '2-7', id: '15', class: 'square checkerboard-square-black', img: '../../assets/images/beige-checker-piece.svg' },
    { squareId: '2-8', id: '16', class: 'square checkerboard-square-red', img: '' },

    { squareId: '3-1', id: '17', class: 'square checkerboard-square-red', img: '' },
    { squareId: '3-2', id: '18', class: 'square checkerboard-square-black', img: '../../assets/images/beige-checker-piece.svg' },
    { squareId: '3-3', id: '19', class: 'square checkerboard-square-red', img: '' },
    { squareId: '3-4', id: '20', class: 'square checkerboard-square-black', img: '../../assets/images/beige-checker-piece.svg' },
    { squareId: '3-5', id: '21', class: 'square checkerboard-square-red', img: '' },
    { squareId: '3-6', id: '22', class: 'square checkerboard-square-black', img: '../../assets/images/beige-checker-piece.svg' },
    { squareId: '3-7', id: '23', class: 'square checkerboard-square-red', img: '' },
    { squareId: '3-8', id: '24', class: 'square checkerboard-square-black', img: '../../assets/images/beige-checker-piece.svg' },

    { squareId: '4-1', id: '25', class: 'square checkerboard-square-black', img: '' },
    { squareId: '4-2', id: '26', class: 'square checkerboard-square-red', img: '' },
    { squareId: '4-3', id: '27', class: 'square checkerboard-square-black', img: '' },
    { squareId: '4-4', id: '28', class: 'square checkerboard-square-red', img: '' },
    { squareId: '4-5', id: '29', class: 'square checkerboard-square-black', img: '' },
    { squareId: '4-6', id: '30', class: 'square checkerboard-square-red', img: '' },
    { squareId: '4-7', id: '31', class: 'square checkerboard-square-black', img: '' },
    { squareId: '4-8', id: '32', class: 'square checkerboard-square-red', img: '' },

    { squareId: '5-1', id: '33', class: 'square checkerboard-square-red', img: '' },
    { squareId: '5-2', id: '34', class: 'square checkerboard-square-black', img: '' },
    { squareId: '5-3', id: '35', class: 'square checkerboard-square-red', img: '' },
    { squareId: '5-4', id: '36', class: 'square checkerboard-square-black', img: '' },
    { squareId: '5-5', id: '37', class: 'square checkerboard-square-red', img: '' },
    { squareId: '5-6', id: '38', class: 'square checkerboard-square-black', img: '' },
    { squareId: '5-7', id: '39', class: 'square checkerboard-square-red', img: '' },
    { squareId: '5-8', id: '40', class: 'square checkerboard-square-black', img: '' },

    { squareId: '6-1', id: '41', class: 'square checkerboard-square-black', img: '../../assets/images/gray-checker-piece.svg' },
    { squareId: '6-2', id: '42', class: 'square checkerboard-square-red', img: '' },
    { squareId: '6-3', id: '43', class: 'square checkerboard-square-black', img: '../../assets/images/gray-checker-piece.svg' },
    { squareId: '6-4', id: '44', class: 'square checkerboard-square-red', img: '' },
    { squareId: '6-5', id: '45', class: 'square checkerboard-square-black', img: '../../assets/images/gray-checker-piece.svg' },
    { squareId: '6-6', id: '46', class: 'square checkerboard-square-red', img: '' },
    { squareId: '6-7', id: '47', class: 'square checkerboard-square-black', img: '../../assets/images/gray-checker-piece.svg' },
    { squareId: '6-8', id: '48', class: 'square checkerboard-square-red', img: '' },

    { squareId: '7-1', id: '49', class: 'square checkerboard-square-red', img: '' },
    { squareId: '7-2', id: '50', class: 'square checkerboard-square-black', img: '../../assets/images/gray-checker-piece.svg' },
    { squareId: '7-3', id: '51', class: 'square checkerboard-square-red', img: '' },
    { squareId: '7-4', id: '52', class: 'square checkerboard-square-black', img: '../../assets/images/gray-checker-piece.svg' },
    { squareId: '7-5', id: '53', class: 'square checkerboard-square-red', img: '' },
    { squareId: '7-6', id: '54', class: 'square checkerboard-square-black', img: '../../assets/images/gray-checker-piece.svg' },
    { squareId: '7-7', id: '55', class: 'square checkerboard-square-red', img: '' },
    { squareId: '7-8', id: '56', class: 'square checkerboard-square-black', img: '../../assets/images/gray-checker-piece.svg' },

    { squareId: '8-1', id: '57', class: 'square checkerboard-square-black', img: '../../assets/images/gray-checker-piece.svg' },
    { squareId: '8-2', id: '58', class: 'square checkerboard-square-red', img: '' },
    { squareId: '8-3', id: '59', class: 'square checkerboard-square-black', img: '../../assets/images/gray-checker-piece.svg' },
    { squareId: '8-4', id: '60', class: 'square checkerboard-square-red', img: '' },
    { squareId: '8-5', id: '61', class: 'square checkerboard-square-black', img: '../../assets/images/gray-checker-piece.svg' },
    { squareId: '8-6', id: '62', class: 'square checkerboard-square-red', img: '' },
    { squareId: '8-7', id: '63', class: 'square checkerboard-square-black', img: '../../assets/images/gray-checker-piece.svg' },
    { squareId: '8-8', id: '64', class: 'square checkerboard-square-red', img: '' },
  ];

  constructor(private sharedService: SharedService, private screenService: ScreenService) { }

  ngOnInit(): void {
    this.sharedService.sendStartGame().subscribe(data => this.addPieces());
    this.sharedService.sendEndGame().subscribe(data => this.newGame = data);
  }

  ngAfterViewInit(): void {
    this.screenService.isBelowLg().subscribe((isBelowLg: BreakpointState) => {
      this.isBelowLg = isBelowLg.matches;
    });

  }

  drop(event: CdkDragDrop<string[]>) {
    console.log(event.container.data[event.currentIndex]['id']);
    if (event.previousContainer === event.container) {
      moveItemInArray(this.items, event.previousIndex, event.currentIndex);
      this.previousIndex = this.items[event.previousIndex];
      this.currentIndex = this.items[event.currentIndex];
      console.log(event.container.data[event.currentIndex]['id']);
      // console.log('this.currentIndex', event.currentIndex);
      // console.log('this.previousIndex', event.previousIndex);
    } else {
      transferArrayItem(event.previousContainer.data,
        event.container.data,
        event.previousIndex,
        event.currentIndex);
      console.log(event.container.data[event.currentIndex]['id']);
      // console.log('this.currentIndex', event.currentIndex);
      // console.log('this.previousIndex', event.previousIndex);
    }
  }

  getId(event, id) {
    // console.log('event.target.id', event.target.id);
    // console.log('id', id);
    // console.log('this.currentIndex', event.currentIndex);
  }


  addPieces() {
    this.newGame = true;
    this.disabled = true;
    this.sharedService.player1Active.next(true);
  }

  onActivePlayer(player) {
  }

  grabChecker(event, index) {
    this.xPointerGrabPosition = event.clientX;
    this.yPointerGrabPosition = event.clientY;
 
  }

  placeChecker(event) {
    this.xPointerReleasePosition = event.clientX;
    this.yPointerReleasePosition = event.clientY;
   console.log('Squares', this.squares);
  }

  moveCheckers3(event) {
    console.log('Event from the pointer capture', event);
  }

  onDragEnded(event: CdkDragEnd, id): void {
    console.log('This is the id of thee item being dragged', id);
    console.log(event.source.getFreeDragPosition());
    let xPointerReleaseMinusGrab = (this.xPointerReleasePosition - this.xPointerGrabPosition);
    let xPointerGrabMinusRelease = (this.xPointerGrabPosition - this.xPointerReleasePosition);
    let yPointerReleaseMinusGrab = (this.yPointerReleasePosition - this.yPointerGrabPosition);
    let yPointerGrabMinusRelease = (this.yPointerGrabPosition - this.yPointerReleasePosition);
    let x;
    let y;
    if (xPointerGrabMinusRelease > 0) {
      x = xPointerGrabMinusRelease;
    } else if (xPointerReleaseMinusGrab > 0) {
      x = xPointerReleaseMinusGrab;
    }

    if (yPointerGrabMinusRelease > 0) {
      y = yPointerGrabMinusRelease;
    } else if (yPointerReleaseMinusGrab > 0) {
      y = yPointerReleaseMinusGrab;
    }
    console.log('x', x);
    console.log('y', y);

    if (this.isBelowLg) {
      if (x === undefined || y === undefined || y > 70 && x > 70 || x < 10 && y < 212 || x < 212 && y < 10) {
        event.source._dragRef.reset();
      }
    } else {

      if (x === undefined || y === undefined || x < 6 || y < 6 || y < 40 && x < 600 || x < 40 && y < 600 || x > 201 && y > 201) {
        event.source._dragRef.reset();
      }

    }
  }

  hideChecker(id: number) {
    console.log('id', id);
    this.hideDirectives.find((p) => p.id === id.toString()).shouldShow = 'none';
  }



}   
mwave317
  • 11
  • 6
  • You need think in variables, **not** in divs. I feel that your best bet is use 64 cdk-drop-list. Yes, a cdk-drop-list can store not only an array else a variable or object. The object can be the position and if has a piece or not. When you drop you check the cdk-drop-list to know the "data" so you can know if the move is allowed or not. You an also know the position from start the drag and the position when end the drop. So you can check all the cdkDropList (use viewChildren to get all the cdkDropList) to change the object when you delete a checked. – Eliseo Jul 20 '22 at 11:28
  • I've updated my code to show the array that I'm using. I wanted to keep track of the checkers on the board using the array. The problem is there is no event.target.id. Since the board is created dynamically using the array. How could I track where it ends up. – mwave317 Jul 20 '22 at 13:33
  • I add an answer with a "start stackblitz" (It's only the part of "drag", there are too much work to do, but I hope can help you with the part of cdk-drag. NOTE: **not** use `../../assets/...`, you should use `assets/...` (see that is nor prefix by ../../ ). See that in my code you need "work" with "id". You "work" with the variables "board" and with the variable in the function "drop". – Eliseo Jul 21 '22 at 17:25

3 Answers3

0

I created a chess in the university and I undertand you. You can solve this in many ways:

  1. Create a state property within your items Array and control the position within it. Or.
  2. Use the Angular Input() and Output() Directives to share data between multiple components. In order to do that, the square should be a component, like this:

    <div *ngIf="let item of items; i = index">
      <div id="item.id" class="red-square">
         <my-cool-component id="1" [item]="item"
            src="../assests/red-checker.svg">
          </my-cool-component>
      </div>
    </div>  

And the Table logic with position could be a variable within your parent component. Think of it like an excel grid where you save each cell with a position to know what chess piece is on it.

I hope this helps you!

  • The board and the checkers are added dynamically from the array. How would I create a state property in Angular to keep track of the checkers in the Array? – mwave317 Jul 20 '22 at 13:34
0

I want develop a few my comments. Imagine a bidimensional array "board"

But first I define an enum to help me define the pieces on the board

export enum TYPE{
  none,
  empty,
  whitePeon,
  whiteChecker,
  blackPeon,
  blackChecker
}

A function initBoard can be like

  initBoard()
  {
    [0,1,2,3,4,5,6,7].forEach(x=>{
      this.board[x]=[0,1,2,3,4,5,6,7].map(y=>({
        x:x,y:y,type:(x%2==0 && y%2==1) || (x%2==1 && y%2==0) ?
              x<3?TYPE.whitePeon:
              x>4?TYPE.blackPeon:
              TYPE.empty:
              TYPE.none
      }))
    })

  }

So, e.g. board[0][0].type=TYPE.None and board0.type=TYPE.whitePeon

If we make a board with cdkDropList in the "white" scaques

<div cdkDropListGroup>
  <div class="flex" *ngFor="let row of board; let rowOdd = odd">
    <ng-container *ngFor="let cell of row; let colOdd = odd">
      <div
        class="cell"
        [class.black]="(rowOdd && colOdd) || (!rowOdd && !colOdd)"
      >
        <div
          *ngIf="cell.type != TYPE.none"
          cdkDropList cdkDropListOrientation="horizontal"
          [cdkDropListData]="cell"
          (cdkDropListDropped)="drop($event)"
        >
          <div cdkDrag *ngIf="cell.type!=TYPE.empty">{{ cell.x }}{{ cell.y }}{{ cell.type }}
          <div *cdkDragPlaceholder class="none"></div>
          </div>
        </div>
      </div>
    </ng-container>
  </div>
</div>

We only need use the function drop

  drop(event: CdkDragDrop<any>){
    console.log(event.container.data,event.previousContainer.data)
  }

See that in event.containerData and event.previousContainer.data we has an element of board. So "only" we need check if the movement is valid, we can position a piece in another place,...

e.g. this

  drop(event: CdkDragDrop<any>){
    if (event.container.data.type==TYPE.empty)
    {
      event.container.data.type=event.previousContainer.data.type
      event.previousContainer.data.type=TYPE.empty
    }
  }

Move one piece if we drag in an empty square in board (we need check also if the movement is valid, is only an example of how use the data of the event to change the "board" array

A "start stackblitz"

NOTE: I prefer use an enum and in the .html show one image or another, but remember that the variables are choose by us, we can use the more confortable

Update go on

When we move a piece, we have in the event.previousContainer.data the "piece" you move and in event.container.data the "square board" where you move the "piece". We can use some auxiliar variables and check if a move is valid or not

  drop(event: CdkDragDrop<any>){

    //to avoid repeat always event.previousContainer.data
    // and event.container.data
    const fromData=event.previousContainer.data;
    const toData=event.container.data;

    if (toData.type!=TYPE.empty)  //If we don't move to an "empty square board"
      return;


    //Calculate how we move in vertical (x) and in horizontal    
    const stepX=toData.x-fromData.x
    const stepY=toData.y-fromData.y

    
    //if we don't move in a "diagonal"
    if (stepX!=stepY || stepX!=-stepY)
      return;

    //the "peon" only move one or two steps
    if (fromData.type==TYPE.whitePeon && stepX>2)
      return;
    if (fromData.type==TYPE.blackPeon && stepX<-2)
      return;


    //If the peon is white and step igual 2
    if (fromData.type==TYPE.whitePeon && stepX==2)
    {

      //get the middle board
      const boardMidle=this.board[fromData.x+1][fromData.y+stepY/2]

      if (boardMidle.type==TYPE.blackPeon || boardMidle.type==TYPE.blackChecker) 
        boardMidle.type=TYPE.empty
      else
        return  
    }
    .....rest of cases...

    if (event.container.data.type==TYPE.empty)
    {
      event.container.data.type=event.previousContainer.data.type
      event.previousContainer.data.type=TYPE.empty
    }
}
Eliseo
  • 50,109
  • 4
  • 29
  • 67
  • Thank you. I'm trying to delete the checker after it's jumped. I looked at the stackblitz but when I jump a checker the jumped checker is still there. How would you delete the jumped checker? – mwave317 Jul 21 '22 at 18:18
  • I update the answer. See that you should think always what we are doing. I write several comments in the code. ee also that you should chechek when you has a whiteChecker and when you has a blackChecker -this pieces can be move a "step" greater than 2 and you need check the "boards" in the diagonal. See also that the x=0 is the upper row -this is the reason that stepX for white peon should be 1 or 2 and stepX for black peon should be -1 or -2. – Eliseo Jul 21 '22 at 19:31
  • Thanks, but the jumped checker is not being deleted. I don't see any comment in the stackbliz. – mwave317 Jul 21 '22 at 21:02
  • The comments was in the update of the answer ((I just comment the stacktblitz too). In stackblitz only "remove" the jumped checker if the "jumped checked" is a "4" – Eliseo Jul 21 '22 at 21:27
  • Thanks but is there a way to use what I wrote to track the checkers. I already have the checkers not being able to move into the red squares. – mwave317 Jul 21 '22 at 22:23
  • Sorry the code you show is uncomplete to know how track to checkers. See that in my code there're no cdkDragList in red squares -so it's impossible drag to the red squares-. The returns makes that happens nothing if a movement is not allowed. In the stackblitz is mannage only when a white peon is move. I can complete the code to check all the possibles cases, but I feel that you can do it also. It's important that you take account that always we are playing with "variables in .ts" (the this.board array). – Eliseo Jul 22 '22 at 07:23
  • I've updated my code to show the entire ts file. I was asking how to track the checkers to be able to delete them. – mwave317 Jul 22 '22 at 13:06
  • In your function drop you has in event.previousContainer.data an object with the "img" and the "index" of your array of the "piece you're moving" and in event.container.data an object with the "img" and the "index" of your array of the "piece or square where you want to move". To move a piece you simple change the "img" property of your array (you put as '' in the index you get the previousContainer and put as value of "img" of you previousContainer in the index of container). you **not** use moveItemInArray **nor** transferArrayItem. – Eliseo Jul 24 '22 at 18:42
  • To remove a piece you need know the "index" of the array to equal his property img to ''. You can use ViewChildren to get all the square board and loop over then checking the position x,y using getBoundingClientRect. In .html `
    ` and `@ViewChildren('square') squares:QueryList`. But I feel it's better that your objects has a property "row" and "column", so you can use find to find the element with row was row+1,col+1 or row+1,col-1 if you're moving from top to bottom
    – Eliseo Jul 24 '22 at 18:50
  • I did change my code. The change is made above so each of the squares would be for example 1-1. I've tried adding the @ViewChildren('square'). I'm having trouble looping over the QueryList. Also in the drop function the event.container.data and the event.previousContainer.data come back as undefined, unless I add the cdkDropList. I've tried adding the cdkDropList and then I get the event.previousContainer.data and the event.container.data. Although, when I move a piece it goes back to its original position – mwave317 Jul 25 '22 at 04:09
  • To relationate all the cdkdropList you should enclosed all in a `
    `. NOTE: I wrote another answer to get a better aproach to make a checkers play
    – Eliseo Jul 25 '22 at 12:50
  • I'm not sure what you mean. Everything is wrapped in a div for the cdkDropListGroup. – mwave317 Jul 25 '22 at 12:55
  • ok, I didn't sure that you wrapped all the cdkDropList. Now you need, in "drop function" change your array (else Angular simply make nothing) – Eliseo Jul 25 '22 at 13:19
0

After re-thinking how to do a checkers play I feel that the "key" is to be captable to get the possibles movements of the pieces.

I imagine a bi-dimensional array board in the way

board=[ 
  [ { "x": 0, "y": 0, "type": -1 }, 
    { "x": 1, "y": 0, "type": 1 }, 
    { "x": 2, "y": 0, "type": -1 }, 
    { "x": 3, "y": 0, "type": 1 }
    ....]
  [ { "x": 0, "y": 1, "type": 1 }, 
    { "x": 1, "y": 1, "type": -1 }, 
    { "x": 2, "y": 1, "type": 1 }, 
    { "x": 3, "y": 1, "type": -1 }
    ....]
 ] 

Type can be none,empty,black,white,blackKing and whiteKing

We need a function that need as arguments: x, y and type and return an array with the possibles movements in the way

  getMovements(x: number, y: number, type: number) {
    const mov:any=[]
    ....
    const elementOfBoard=this.board[index]
    const elementDelete=this.board[anotherIndex] || null
    ...
    mov.push(move:elementOfBoard,delete:elementDelete)
    ...
    return mov;
  }

So can return, e.g.

[ 
  { "move": { "x": 5, "y": 2, "type": 0 }, 
    "delete": { "x": 4, "y": 3, "type": 1 } 
  }, 
  { "move": { "x": 2, "y": 3, "type": 0 }, 
    "delete": null } 
] 

Really don't return a new object, else one element of this.board so our drop function is more simple

  drop(event: CdkDragDrop<any>) {
    const fromData = event.previousContainer.data;
    const toData = event.container.data;

      const allowMovements = this.getMovements(
        fromData.x,
        fromData.y,
        fromData.type
      );
      const move = allowMovements.find((x) => x.move == toData);
      if (move) { //<--(move.move) is an element of board
         ....
         fromData.type=TYPE.empty;

         move.move.type=TYPE.pieceWeMove

         if (move.delete) { //<---is an element of board
           ...
           move.delete.type=TYPE.empty
         }
      }
  }
Eliseo
  • 50,109
  • 4
  • 29
  • 67
  • First I need to get the cdkDropList to work. The checkers won't stay to where they are moved. That needs to be fixed first. – mwave317 Jul 25 '22 at 13:21
  • if you "reach" the function "drop", just use `console.log(event.container.data)` if because the drop is working. Then you need change the array with the data of event.container.data and event.previousContainer.data. If you don't change the array, looks like you don't dropped anything – Eliseo Jul 25 '22 at 14:39
  • I've been getting the event.container.data with the cdkDropList. Using my code, how would I change the array? – mwave317 Jul 25 '22 at 15:37
  • E.g., to move: `event.container.data.img=event.previousContainer.data.img;event.previousContainer.data.img=''` you see that the "checker move" (really you only change the array). To check if you move to a square with no piece you use `if event.container.data.img=='' && event.container.data.class=='square checkerboard-square-white'` or if you want to check that the scare is not red `if event.container.data.class!='square checkerboard-square-red'`. See that your cdk-drag-drop-list has as "data" `item` – Eliseo Jul 25 '22 at 16:37
  • Thanks, I added the event.container.data.img=event.previousContainer.data.img;event.previousContainer.data.img='' and now I can move the checker to the correct spot. Using my code, how would I loop over the queryList of the squares variable. I need to loop over that to get the id of the jumped checker. I keep getting an error message when I try to loop over it. – mwave317 Jul 25 '22 at 17:55
  • You can loop over the QueryList `this.squares.forEach((x,i)=>{console.log(x.nativeElement.getBoundingClientRect();console.log(this.items[i])}` or you can simply loop over the array items and ask about the property squareId: `this.items.forEach(x=>{console.log(x.squareId)})`. Also, as you know the "squareId" of the event.previousContainer.data.squareId and event.container.data.squareId, you can calculate the "squareId" over you jumped and use `this.items.find(x=>x.squareId==calculateSquareId).img=''` – Eliseo Jul 25 '22 at 18:03